Jump to:

22977 Posts in 11747 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Adding CMS Fields fails... me or SS?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 704 Views
  • AlaVive
    Avatar
    Community Member
    42 Posts

    Adding CMS Fields fails... me or SS? Link to this post

    I'm still a bit green to this, so please forgive me.

    I'm using 2.3.2.

    I created a banner upload in page.php to allow a unique banner image for each page. It works beautifully.

    Then, I tried to create the staff page, per the tutorial.

    But, the tab I've created for the staff photo isn't showing up in the CMS.

    See my code below:

    Page.php

    <?php

    class Page extends SiteTree {
       
       public static $db = array(
       );
       
       public static $has_one = array(
       'BannerImage' => 'Image'
       );
       
       function getCMSFields() {
    $fields = parent::getCMSFields();
    if($this->ClassName == "Page"){
       $fields->addFieldToTab("Root.Content.PgBannerImage", new ImageField("BannerImage"));
       }
    return $fields;
    }

    }

    class Page_BannerImage extends Image {

    function generatePageBanner($gd) {
    $gd->setQuality(80);
    return $gd->paddedResize(890,200);
    }

    }

    class Page_Controller extends ContentController {
       
       public function init() {
          parent::init();

          // Note: you should use SS template require tags inside your templates
          // instead of putting Requirements calls here. However these are
          // included so that our older themes still work
          //Requirements::themedCSS("layout");
          //Requirements::themedCSS("typography");
          //Requirements::themedCSS("form");
       }

       
       /**
        * Site search form
        */
       function SearchForm() {
          $searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : 'Search';
          $fields = new FieldSet(
           new TextField("Search", "", $searchText)
           );
          $actions = new FieldSet(
           new FormAction('results', 'Search')
           );

           return new SearchForm($this, "SearchForm", $fields, $actions);
       }
       
       /**
        * Process and render search results
        */
       function results($data, $form){
           $data = array(
           'Results' => $form->getResults(),
           'Query' => $form->getSearchQuery(),
           'Title' => 'Search Results'
           );

           return $this->customise($data)->renderWith(array('Page_results', 'Page'));
       }
       
    }
    ?>

    ProductsPage.php (It will be used to display products, rather than staff, so it's named accordingly...)

    <?php
    /**
    * Defines the ProductsPage page type
    */
    class ProductsPage extends Page {
    static $db = array(

    );
    static $has_one = array(
    'ProdPhoto' => 'Image'
    );
    }

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Images", new ImageField("ProdPhoto"));    
    return $fields;
    }

    class ProductsPage_Controller extends Page_Controller {

    }

    ?>

    I've my pages working correctly to display the information. I just can't get the photos to upload.

    Please let me know if more information is needed or if I'm making an obvious error.

    Thanks!

  • AlaVive
    Avatar
    Community Member
    42 Posts

    Re: Adding CMS Fields fails... me or SS? Link to this post

    OK. I'm lost.

    I tried to add a simple HTML Editor field to the ProductsPage.php, and it didn't show up, either.
    ProductsPage.php

    <?php
    /**
    * Defines the ProductsPage page type
    */
    class ProductsPage extends Page {
    static $db = array(
    'ProdIntro' => 'HTMLText'

    );
    static $has_one = array(
    'ProdPhoto' => 'Image'
    );
    }

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Intro", new HtmlEditorField("ProdIntro"));
    $fields->addFieldToTab("Root.Content.Images", new ImageField("ProdPhoto"));    
    return $fields;
    }

    class ProductsPage_Controller extends Page_Controller {

    }

    ?>

    Is this something I'm doing/not doing?

    It shows that it's building the database as it's told, but the CMS isn't showing any change other than adding the different holder and page types to the create menu.

    Thanks (again... in advance).

  • AlaVive
    Avatar
    Community Member
    42 Posts

    Re: Adding CMS Fields fails... me or SS? Link to this post

    Sorry to litter the forums with questions that may not seem to make sense. At this point, I'll rephrase to hopefully simplify.

    Why was I able to extend my CMS and page types two days ago, but now it's not working?

    It works for my home page type, and but it's not working for any of the page types I've tried since. Since my last post, I've literally copied and pasted from the tutorials in an attempt to ensure I'm not making some error that's screwing this all up. It modifies the database and adds the page types to the options, but it offers no fields, whether added to the main or content sections.

    I'm sure someone more seasoned in SilverStripe can help. I'm at a loss.

    Please?

  • AlaVive
    Avatar
    Community Member
    42 Posts

    Re: Adding CMS Fields fails... me or SS? Link to this post

    Ok. Solution found:

    http://www.silverstripe.org/archive/show/196427#post196427

    A full day of work because of a "}."

    I must declare that I'm not a complete dork-- just completely overworked ;-).

    704 Views
Page: 1
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.