17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2283 Views |
-
SiteTree selection not saved

3 September 2008 at 8:53am
Hi Everyone
I'm a newbie on Silverstripe and have a question. I created a SiteTree field in silverstripe and it shows up in my tab. However, when I choose a page from the sitetree and click save, it doesn't save anything. Here's the code in Page.php:
static $has_one = array(
'Photo' => 'Image',
'PhotoLink' => 'SiteTree',
'Photo2' => 'Image',
'PhotoLink2' => 'SiteTree',
'Photo3' => 'Image',
'PhotoLink3' => 'SiteTree'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$treedropdownfield = new TreeDropdownField("PhotoLink", "Choose a page that wish to link to:", "SiteTree");
$treedropdownfield2 = new TreeDropdownField("PhotoLink2", "Choose a page that wish to link to:", "SiteTree");
$treedropdownfield3 = new TreeDropdownField("PhotoLink3", "Choose a page that wish to link to:", "SiteTree");
$fields->addFieldToTab("Root.Content.RightImages", new ImageField('Photo'));
$fields->addFieldToTab("Root.Content.RightImages", new TextField('PhotoText'));
$fields->addFieldToTab("Root.Content.RightImages", $treedropdownfield);
$fields->addFieldToTab("Root.Content.RightImages", new ImageField('Photo2'));
$fields->addFieldToTab("Root.Content.RightImages", new TextField('PhotoText2'));
$fields->addFieldToTab("Root.Content.RightImages", $treedropdownfield2);
$fields->addFieldToTab("Root.Content.RightImages", new ImageField('Photo3'));
$fields->addFieldToTab("Root.Content.RightImages", new TextField('PhotoText3'));
$fields->addFieldToTab("Root.Content.RightImages", $treedropdownfield3);return $fields;
}As you can it's pretty simply, but why doesn't Silverstripe save the selected page?
And a second question when I succed in saving an internal page, how do I acces the site in my template Page.ss
Many thanx
Joel
-
Re: SiteTree selection not saved

3 September 2008 at 10:02am
Hi joelg,
when you visit the page in the CMS, do all the fields appear? If so, its probably that you ahvent rebuilt the database. To do this, visit yoursite.com/db/build?flush - this will create all the new DB fields automatically.
If youve already done this, you need to make sure that your adding this code to the Page, not the Page_Controller class.
-
Re: SiteTree selection not saved

3 September 2008 at 6:23pm Last edited: 3 September 2008 6:23pm
Hi Ajshort
I did rebuild the database and that wasn't the issue, however I'v worked out a solution that works for know, but i'm pretty sure it's not best practice. I created three Integers, and that makes it possible to save the siteTree selection. Here's mys Page.php code:
class Page extends SiteTree {
static $db = array(
'PhotoText' => 'Text',
'PhotoText2' => 'Text',
'PhotoText3' => 'Text',
'PhotoLink' => 'Int',
'PhotoLink2' => 'Int',
'PhotoLink3' => 'Int'
);
static $defaults = array(
);static $has_one = array(
'Photo' => 'Image',
'PhotoLink' => 'Page',
'Photo2' => 'Image',
'PhotoLink2' => 'Page',
'Photo3' => 'Image',
'PhotoLink3' => 'Page'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.RightImages", new ImageField('Photo'));
$fields->addFieldToTab("Root.Content.RightImages", new TextField('PhotoText'));
$fields->addFieldToTab("Root.Content.RightImages", new TreeDropdownField("PhotoLink", "Choose a page that wish to link to:", "SiteTree"));
$fields->addFieldToTab("Root.Content.RightImages", new ImageField('Photo2'));
$fields->addFieldToTab("Root.Content.RightImages", new TextField('PhotoText2'));
$fields->addFieldToTab("Root.Content.RightImages", new TreeDropdownField("PhotoLink2", "Choose a page that wish to link to:", "SiteTree"));
$fields->addFieldToTab("Root.Content.RightImages", new ImageField('Photo3'));
$fields->addFieldToTab("Root.Content.RightImages", new TextField('PhotoText3'));
$fields->addFieldToTab("Root.Content.RightImages", new TreeDropdownField("PhotoLink3", "Choose a page that wish to link to:", "SiteTree"));return $fields;
}function getUrl() {
return DataObject::get_by_id("Page",$this->PhotoLink);
}
function getUrl2() {
return DataObject::get_by_id("Page",$this->PhotoLink2);
}
function getUrl3() {
return DataObject::get_by_id("Page",$this->PhotoLink3);
}
}And here's a little part of my template section...
<div id="foto"><a href="<% control getUrl %> $Link <% end_control %>">$Photo.SetWidth(230)</a>
<div id="fotoText"><a href="<% control getUrl %> $Link <% end_control %>">$PhotoText</a></div></div>As you can see, I'm trying to create some sort of banner images, which users can click and be redirected to another page on the websites. This solution works, but it could be better.
Thanx for you help:-) And please let me know if there's an easier solution...
Joel
-
Re: SiteTree selection not saved

5 December 2008 at 6:47am Last edited: 5 December 2008 6:47am
Hey Joelg... I'm looking for the same solution. Did you have any issues with your method after you tried it ?
-
Re: SiteTree selection not saved

5 December 2008 at 8:58am
Instead of using integers, keep the SiteTree types, but use the ID field in the TreeDropDownField, so
new TreeDropdownField("PhotoLinkID"...
| 2283 Views | ||
|
Page:
1
|
Go to Top |



