Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

Adding CMS Fields fails... me or SS?


Reply


4 Posts   790 Views

Avatar
AlaVive

Community Member, 42 Posts

4 August 2009 at 11:34am

Edited: 05/08/2009 6:54am

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!

Avatar
AlaVive

Community Member, 42 Posts

4 August 2009 at 1:18pm

Edited: 05/08/2009 4:57am

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).

Avatar
AlaVive

Community Member, 42 Posts

5 August 2009 at 4:54am

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?

Avatar
AlaVive

Community Member, 42 Posts

5 August 2009 at 6:58am

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 ;-).