Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Let's Just Pretend That I'm A Moron...

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1 2
Go to End
Author Topic: 4891 Views
  • revstevens
    Avatar
    Community Member
    9 Posts

    Let's Just Pretend That I'm A Moron... Link to this post

    That isn't really very hard to do, so it seems like a good place to start.

    Let me start by saying that I know HTML and CSS. However, I don't know jack about PHP.

    I'm trying to find a good CMS that can be implemented in future projects and like the interface that SS has to offer. I thought the best place to start would be on my own site, which I developed in Dreamweaver, and am building the template for in SS.

    *EDITED FROM HERE ON

    I actually just came to a realization that, really, I need 3 separate editable areas.

    1. main content
    2. side content
    3. Another area below the main content that shows a list of recent work

    I have all the styles defined, but how do I actually create more than one editable area in the CMS?

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Let's Just Pretend That I'm A Moron... Link to this post

    Its pretty simple and Im it should be on the wiki but I cant find it! So i might write this up on there for future reference as well but here it goes. You need 3 steps

    Step 1. Add the 2 New Areas to your database

    Open up mysite/code/Page.php in your text editor and add these 2 entries inside the static $db = array(); bit

    'SidebarContent' => 'HTMLText' , 'RecentWorkContent' => 'HTMLText'

    Step 2. Add the 2 New Areas to your CMS editor

    In that same file you should see a function getCMSFields() function. You need to use this to add 2 fields to the CMS

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Main", new HTMLEditorField("SidebarContent"));
    $fields->addFieldToTab("Root.Content.Main", new HTMLEditorField("RecentWorkContent"));

    return $fields;
    }

    Now you just need to rebuild your sites database by visiting http://yoursite.com/db/build?flush=1 and then view the admin section to make sure your fields have been added! But you have 1 more step! You need to see it from the front end.

    Step 3. Tell the template where to output these to

    Open up a template file - which ever one you want to output the content too, For this say themes/blackcandy/templates/Layout/Page.ss and add the 2 fields

    $SidebarContent
    ..
    $RecentWorkContent

  • revstevens
    Avatar
    Community Member
    9 Posts

    Re: Let's Just Pretend That I'm A Moron... Link to this post

    OK, if this works, I'm going to love you forever, in a mostly straight way.
    I'll be trying it out in a bit and I'll let you know if I manage to foul things up at all.

    Thanks again.

  • revstevens
    Avatar
    Community Member
    9 Posts

    Re: Let's Just Pretend That I'm A Moron... Link to this post

    Alright, I put the info into the page.php file, which now looks like this:

    <?php

    class Page extends SiteTree {
       static $db = array(
       'ContentSub' => 'HTMLText' , 'RecentWork' => 'HTMLText'
       );
       
       static $defaults = array(
       );

       function getCMSFields() {
       $fields = parent::getCMSFields();
       $fields->addFieldToTab("Root.Content.Main", new HTMLEditorField("ContentSub"));
       $fields->addFieldToTab("Root.Content.Main", new HTMLEditorField("RecentWork"));
       return $fields;
    }

    class Page_Controller extends ContentController {
       function init() {
          parent::init();
          
          Requirements::themedCSS("layout");
          Requirements::themedCSS("typography");
          Requirements::themedCSS("colors");
       }
    }

    ?>

    Let me know if there is a problem there, because, after I do that I flush the database, but it doesn't flush very far. It only goes to here:

    Building Database

    Creating database tables

    Newsletter
    Newsletter_SentRecipient
    Newsletter_Recipient
    NewsletterType
    PageComment
    Email_BounceRecord
    Email_BlackList
    PageView
    SiteTree
    QueuedEmail
    File
    EditableCheckboxOption
    EditableDropdownOption
    EditableFormField
    EditableRadioOption
    SubmittedForm
    SubmittedFormField
    Group
    Member
    Member_UnsubscribeRecord
    Permission
    Widget
    WidgetArea
    GhostPage

    What am I doing wrong here? Cause I know this is my fault.

  • bennybtl
    Avatar
    Community Member
    12 Posts

    Re: Let's Just Pretend That I'm A Moron... Link to this post

    *edited*

  • revstevens
    Avatar
    Community Member
    9 Posts

    Re: Let's Just Pretend That I'm A Moron... Link to this post

    Help?

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Let's Just Pretend That I'm A Moron... Link to this post

    "Oh my god, it's a ghost page!"

    Try generating the database from scratch - ie, drop the current database, or change the database in your _config.php and see if it will generate a new database correctly.

    I have experienced issues where it will get hung up changing existing tables and the quickest solution has been to drop and rebuild.

    Of course, if you already have lots of content in your database, you might not want to do that, but if you rename the old database and rebuild it, it would only take a bit of SQL to pull your data back across.

    Other than that, your code should work. If the actions above don't solve the issue, post back and I'll set up your code and see what happens.

  • revstevens
    Avatar
    Community Member
    9 Posts

    Re: Let's Just Pretend That I'm A Moron... Link to this post

    I'll try. I'm not much of a back-end code editor, but I think I can figure it out. It may take me a few days to get back to you and let you know how it went, so please don't think I've given up. I appreciate the help.

    4891 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.