Jump to:

5540 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » how do I add multiple $allow_children?

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

Page: 1
Go to End
Author Topic: 1452 Views
  • Daimz
    Avatar
    Community Member
    36 Posts

    how do I add multiple $allow_children? Link to this post

    I am trying to use multiple children in order to pull two set of information in to my HomePage this is what I have done:

    class HomePage extends Page {
    static $db = array(
    );
    static $has_one = array(
    );
    static $allowed_children = array('PortfolioPage');
    static $allowed_children = array('PortfolioFeaturePage');


    I am getting this error returning:

    Fatal error: Cannot redeclare HomePage::$allowed_children in /home4/arctosde/public_html/silverstripe/mysite/code/HomePage.php on line 12

    Is there I way I can use two $allow_children? or how eles could I acheive this?
    thanx in advance

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: how do I add multiple $allow_children? Link to this post

    You cannot redeclare it twice - thats why its an array object - an array object can have multiple elements.

    static $allowed_children = array('PortfolioPage', 'PortfolioFeaturePage');

    I an not sure how effective $allowed_children is. As it doesn't hide the other options from the dropdown.

  • Daimz
    Avatar
    Community Member
    36 Posts

    Re: how do I add multiple $allow_children? Link to this post

    Ok cool thanx so much.
    If $allow_children is not what you think would be the most effective then what would you recommend. (I only know a small amount of code so I am still learning)

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: how do I add multiple $allow_children? Link to this post

    well static $default_child = 'PortfolioPage'; sets the default page type for the section.

  • Daimz
    Avatar
    Community Member
    36 Posts

    Re: how do I add multiple $allow_children? Link to this post

    Ok. Um well I am very confused I don't know if you have seen my other post http://silverstripe.org/customising-the-cms/show/265849#post265849 But I have had a problem with using image fields and now always waiting to fill it with an image. I am trying to create a portfolio site and part of that is a feature section on my home page which works. Well sort of. It does to the point of pull the image of the ImageFeild and then displaying them but as it only a feature image not every page I have would have an image to fill the feild and thus it would attempt to show the image for that page but I never put one there so it shows a empty space. I am wanting something which just shows only image I have deliberatly put in and ignore the empty ones.

    So basicly thats how I got to the point I am at now where I thought perhaps instead of having one page with the feature imagfeild I would just create a two pages one for pages with featured images and one for ordinary portfolio work.

    Am I making this really difficult for my self and missing something?

  • Daimz
    Avatar
    Community Member
    36 Posts

    Re: how do I add multiple $allow_children? Link to this post

    I just thought I would what I wrote in the other question here so it's easier to follow.

    I have just notice a slight problem in how I have set up my image feilds. I am building a portfolio site and I wanted to have images that would be added to a featured section on the site which I did like this:

    PortfolioPage.php

    <?php
    /**
    * Defines the ArticlePage page type
    */
    class PortfolioPage extends Page {
       static $db = array(
    'Date' => 'Date',
    'Author' => 'Text',
    'Client' => 'Text',
    'Task' => 'Text',
    'Role' => 'Text'
    );
    static $has_one = array(
    'FeatureWork' => 'PortfolioPage_FeatureWork',
    'RecentThumb' => 'PortfolioPage_RecentThumb',
    'PortImage' => 'Image'
    );
    function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab('Root.Content.Main', new CalendarDateField('Date'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('Author'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('Client'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('Task'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('Role'), 'Content');
    $fields->addFieldToTab('Root.Content.Images', new ImageField('FeatureWork'));
    $fields->addFieldToTab('Root.Content.Images', new ImageField('RecentThumb'));
    $fields->addFieldToTab('Root.Content.Images', new ImageField('PortImage'));
       
    return $fields;
    }

    static $icon = "themes/tutorial/images/treeicons/news";

    static $defaults = array(
    'ProvideComments' => true
    );

    }

    class PortfolioPage_Controller extends Page_Controller {

    }

    class PortfolioPage_FeatureWork extends Image {

    function generatePortfolioFeature($gd) {
    $gd->setQuality(100);
    return $gd;
    }
    }
    class PortfolioPage_RecentThumb extends Image {

    function generatePortfolioRecentThumbnail($gd) {
    $gd->setQuality(100);
    return $gd;
    }
    }

    ?>
    HomePage.php

    <?php
    /**
    * Defines the HomePage page type
    */

    class HomePage extends Page {
    static $db = array(
    );
    static $has_one = array(
    );
    static $allowed_children = array('PortfolioPage');

    static $icon = "themes/tutorial/images/treeicons/home";
    }

    class HomePage_Controller extends Page_Controller {

    /*Function calls Articles on to the homepage showing only the first Paragraph*/

    function LatestNews($num=5) {
    $news = DataObject::get_one("PortfolioHolder");
    return ($news) ? DataObject::get("PortfolioPage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
    }
    function RecentPortfolioUpdate($num=4) {
    $news = DataObject::get_one("PortfolioHolder");
    return ($news) ? DataObject::get("PortfolioPage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
    }

       
    }
    ?>

    HomePage.ss

    <div id="feature">
    <% control LatestNews %>
    <a href="$Link" title="Read more on &quot;{$Title}&quot;"><img src="$FeatureWork.PortfolioFeature.URL" id="feature_image"></a>
    <% end_control %>
    </div>

    All this does as it is meant to and shows the images in the FeatureWork ImageFeild where they should be in the jQuery as you can see HERE. However my problem is that because it is a featured section I only want it to show pages where I have actually uploaded a image in the FeatureWork ImageFeild. Oviously every time I create a new PortfolioPage I will have that image field their but I wont always be adding an image to it, and at the moment when I dont I get an empty block in the image slider because it wants to add an image.

  • Daimz
    Avatar
    Community Member
    36 Posts

    Re: how do I add multiple $allow_children? Link to this post

    Ok I have found a work around but creating two pages one for featured works and one for ordinary works. And I have one Problem now I am every page contains a thumbnail that will be displayed on the main page. When I created the new PortfolioPage.php it told me that I cannot re declare the RecentThumbs image as it was already declared in the PortfolioPage.php.

    like this:

    class PortfolioPage_RecentThumb extends Image {

    function generatePortfolioRecentThumbnail($gd) {
    $gd->setQuality(100);
    return $gd;
    }
    }


    and it is called on my home page like this:

    <img src="$RecentThumb.PortfolioRecentThumbnail.URL" id="feature_image">

    So what I was thinking is if change Class PortfolioPage_RecentThumb extend Image{ to Class PortfolioItemPage_RecentThumb extend Image{ on the PortfolioItemPage.php can could potentially call both images in to the <img> tag on the Home page.

    Something like this:
    [code
    <a href="$Link" title="Read more on &quot;{$Title}&quot;"><img src="'$RecentThumb.PortfolioRecentThumbnail.URL' , '$RecentThumb.PortfolioItemRecentThumbnail.URL'" id="feature_image"></a>

    I know thats not right but thats where I am needing help because I don't understand the code to do it. I think maybe some kind of IF STATMENT to change image depending on page type?
    I would really appreciate the help.
    Thanx in advance

  • Daimz
    Avatar
    Community Member
    36 Posts

    Re: how do I add multiple $allow_children? Link to this post

    I figured it out.
    just had to use the <% if FeatureWork %>

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