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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Template Questions /

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

Newbe and template question


Go to End


880 Views

Avatar
jonny76

Community Member, 1 Post

25 November 2011 at 1:27am

Hi all,

Just started using silverstripe and have come across a problem and cant find the solution, wondered if anyone could help?

I have used a pre built module for creating custom menu's.

http://www.silverstripe.org/all-other-modules/show/11290?start=0

This adds the adds simple custom menus. I have then extended the a custom HomePage Class to be able to save a menu to a page.

Ok this all works great.

Next In the AboutPage_controller Class Ive added this function

public function returnRightMenu()
    {
        $menuID = $this->dataRecord->RMenuID;
        if(DataObject::get_one('CustomMenuHolder',"ID = '$menuID'")) 
        {
        
             $menu = DataObject::get_one('CustomMenuHolder',"ID = '$menuID'");

             if($menu->Order)
             $order = explode(',', $menu->Order);

             $pages = new DataObjectSet();

             if(isset($order) && is_array($order) && count($order) > 0) 
             {
                foreach($order as $item) 
                {
                    $pages->push($menu->Pages()->find('ID',$item));
                }
             } 
             else 
             {
                foreach($menu->Pages() as $item) 
                {
                    $pages->push($item);
                }
            }

            if($pages->exists())

            return $pages;
        }
    }

This runs off and retrieves the the menu data which is returned as array of page data objects.

Next. On the AboutPage.ss file i have created a custom controller

<% control returnRightMenu  %>

$Title<br />

<% end_control %>

This throws a white screen and in the error logs i get

PHP Fatal error: Call to a member function obj() on a non-object in

If i replace the "$Title" part with static "Title" it loops throught the correct amount of menu options and displays the word Title the corect amount of times.

My question is, how can I get it to display the dynamic content from the controller?

I assume $Title would work and it doesnt. I also did a print_r of what is returned from the returnRightMenu() function and got this

DataObjectSet Object
(
[items:protected] => Array
(
[0] =>
[1] => Page Object
(
[destroyed] =>
[record:protected] => Array
(
[ClassName] => Page
[Created] => 2011-11-22 17:10:44
[LastEdited] => 2011-11-22 17:10:55
[URLSegment] => technology
[Title] => Technology
[MetaTitle] => Technology
[ShowInMenus] => 1
[ShowInSearch] => 1
[ProvideComments] => 0
[Sort] => 3
[HasBrokenFile] => 0
[HasBrokenLink] => 0
[Status] => Published
[CanViewType] => Inherit
[CanEditType] => Inherit
[Version] => 2
[ParentID] => 2
[ID] => 20
[RecordClassName] => Page
)

[changed:private] => Array
(
)

[original:protected] => Array
(
[ClassName] => Page
[Created] => 2011-11-22 17:10:44
[LastEdited] => 2011-11-22 17:10:55
[URLSegment] => technology
[Title] => Technology
[MetaTitle] => Technology
[ShowInMenus] => 1
[ShowInSearch] => 1
[ProvideComments] => 0
[Sort] => 3
[HasBrokenFile] => 0
[HasBrokenLink] => 0
[Status] => Published
[CanViewType] => Inherit
[CanEditType] => Inherit
[Version] => 2
[ParentID] => 2
[ID] => 20
[RecordClassName] => Page
)

[components:protected] =>
[brokenOnDelete:protected] =>
[brokenOnWrite:protected] =>
[componentCache:protected] =>
[iteratorPos:protected] =>
[iteratorTotalItems:protected] =>
[failover:protected] =>
[customisedObject:protected] =>
[objCache:private] => Array
(
)

[class] => Page
[extension_instances:protected] => Array
(
[CustomMenuDecorator] => CustomMenuDecorator Object
(
[owner:protected] =>
[ownerBaseClass:protected] => SiteTree
[ownerRefs:private] => 0
[class] => CustomMenuDecorator
)

[Hierarchy] => Hierarchy Object
(
[markedNodes:protected] =>
[markingFilter:protected] =>
[_cache_numChildren:protected] =>
[owner:protected] =>
[ownerBaseClass:protected] => SiteTree
[ownerRefs:private] => 0
[class] => Hierarchy
)

[Versioned] => Versioned Object
(
[stages:protected] => Array
(
[0] => Stage
[1] => Live
)

[defaultStage:protected] => Stage
[liveStage:protected] => Live
[migratingVersion] =>
[owner:protected] =>
[ownerBaseClass:protected] => SiteTree
[ownerRefs:private] => 0
[class] => Versioned
)

)

)

[2] => Page Object
(
[destroyed] =>
[record:protected] => Array
(
[ClassName] => Page
[Created] => 2011-11-22 17:11:28
[LastEdited] => 2011-11-22 17:11:38
[URLSegment] => excellence
[Title] => Excellence
[MetaTitle] => Excellence
[ShowInMenus] => 1
[ShowInSearch] => 1
[ProvideComments] => 0
[Sort] => 4
[HasBrokenFile] => 0
[HasBrokenLink] => 0
[Status] => Published
[CanViewType] => Inherit
[CanEditType] => Inherit
[Version] => 2
[ParentID] => 2
[ID] => 22
[RecordClassName] => Page
)

[changed:private] => Array
(
)

[original:protected] => Array
(
[ClassName] => Page
[Created] => 2011-11-22 17:11:28
[LastEdited] => 2011-11-22 17:11:38
[URLSegment] => excellence
[Title] => Excellence
[MetaTitle] => Excellence
[ShowInMenus] => 1
[ShowInSearch] => 1
[ProvideComments] => 0
[Sort] => 4
[HasBrokenFile] => 0
[HasBrokenLink] => 0
[Status] => Published
[CanViewType] => Inherit
[CanEditType] => Inherit
[Version] => 2
[ParentID] => 2
[ID] => 22
[RecordClassName] => Page
)

[components:protected] =>
[brokenOnDelete:protected] =>
[brokenOnWrite:protected] =>
[componentCache:protected] =>
[iteratorPos:protected] =>
[iteratorTotalItems:protected] =>
[failover:protected] =>
[customisedObject:protected] =>
[objCache:private] => Array
(
)

[class] => Page
[extension_instances:protected] => Array
(
[CustomMenuDecorator] => CustomMenuDecorator Object
(
[owner:protected] =>
[ownerBaseClass:protected] => SiteTree
[ownerRefs:private] => 0
[class] => CustomMenuDecorator
)

[Hierarchy] => Hierarchy Object
(
[markedNodes:protected] =>
[markingFilter:protected] =>
[_cache_numChildren:protected] =>
[owner:protected] =>
[ownerBaseClass:protected] => SiteTree
[ownerRefs:private] => 0
[class] => Hierarchy
)

[Versioned] => Versioned Object
(
[stages:protected] => Array
(
[0] => Stage
[1] => Live
)

[defaultStage:protected] => Stage
[liveStage:protected] => Live
[migratingVersion] =>
[owner:protected] =>
[ownerBaseClass:protected] => SiteTree
[ownerRefs:private] => 0
[class] => Versioned
)

)

)

)

[odd:protected] => 0
[first:protected] => 1
[last:protected] =>
[current:protected] =>
[pageStart:protected] =>
[pageLength:protected] =>
[totalSize:protected] =>
[paginationGetVar:protected] => start
[iteratorPos:protected] =>
[iteratorTotalItems:protected] =>
[failover:protected] =>
[customisedObject:protected] =>
[objCache:private] => Array
(
)

[class] => DataObjectSet
[extension_instances:protected] => Array
(
)

)