22397 Posts in 6743 Topics by 2748 members
|Go to End|
15 January 2009 at 12:15pm Last edited: 15 January 2009 12:58pm
I have created a site map based on the tutorial. This site map works great. I want to add a checkbox to the CMS that will hide a page from the site map. I see that currently I can do it by page type like the tutorial hides the error page. However I want to be able to click a checkbox on any page to hide it. I have added
'HideInSiteMap' => 'Boolean' to the $db array and
$fields->addFieldToTab("Root.Behaviour", new CheckboxField("HideInSiteMap", "Hide from site map?"),'ShowInSearch'); to getCMSFields in the Page class.
This works and creates a table called Page which puts the page ID next to the ideInSiteMap column and does put a 1 or 0 depending on the value of the checkbox in CMS.
So far this all works as I had expected.
Now in the sitemap.php file I cannot figure out how to access the HideInSiteMap values in the Page table.
if(!($page instanceof ErrorPage) && $page->Title != $this->Title && $page->HideInSiteMap != 1)
But $page->Title works because it is getting that from the sitetree table not the page table.
So how do I access the page table?
15 January 2009 at 2:43pm Last edited: 15 January 2009 2:44pm
That should work.
Don't worry too much about what tables are created. the sapphire ORM looks after table creation and won't make a Page table until it needs to. The Page table didn't exist before because it didn't need to add any more fields to the data class (since $db was empty).
Put it this way - Page is a type of SiteTree - so when you get a page, the ORM gets the SiteTree record, and adds the fields it *also* finds in the Page table. The Page table just adds fields that you define in Page.php (in $db), but retains all the properties and methods of SiteTree too
|Go to Top|