3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 674 Views |
-
Author as a Dataobject

28 October 2010 at 3:27am Last edited: 28 October 2010 3:29am
Hey guys,
I've hit a bit of a problem with a site I'm developing.
I have a DataObject called Staff that is managed via StaffPage (holds information on each member of staff; name, role, description, headshot, email address), outputting to the StaffPage is easy. However I'm wanting to be able to use the same information in the site's NewsPage and ArticlePage as the Author information - so at the end of each NewsPage/ArticlePage you get a wee bit of blurb about the writer.
I've been trying for most of the day to get this to work and I've managed to get a dropdown loaded up in the CMS (thanks to ssbits.com's dropdown population tutorial), however it wont save the information across - and I'm not convinced I've done it right anyway...
Here is the code in NewsPage:
<?php
/**
* Defines the NewsPage page type
*/
class NewsPage extends Page {
static $db = array(
'Date' => 'Date'
);
static $has_one = array(
'Staff' => 'Staff'
);
static $many_many = array(
);function getMyObjectOptions()
{
if($Pages = DataObject::get('Staff'))
{
return $Pages->map('ID', 'StaffName', 'Please Select');
}
else
{
return array('No Staff found');
}
}
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new DatePickerField('Date', 'Date'));
$fields->addFieldToTab("Root.Content.Main", new DropdownField(
'Staff',
'Please choose a Staff Member',
$this->getMyObjectOptions()
));
return $fields;
}
}class NewsPage_Controller extends Page_Controller {
}
Presumably someone has done this before, I'm just stuck at this point.
Thanks,
Stewart
-
Re: Author as a Dataobject

29 October 2010 at 8:04pm
I'm not sure about this one since I usually don't use dropdowns but try calling it StaffID instead of Staff.
$fields->addFieldToTab("Root.Content.Main", new DropdownField(
'StaffID',
'Please choose a Staff Member',
$this->getMyObjectOptions()
));StaffID is what the actual field in the database is called so that might be why it's not saving. Let me know if it works.
-
Re: Author as a Dataobject

2 November 2010 at 3:05am Last edited: 2 November 2010 3:11am
Yeah that worked perfectly thanks!
| 674 Views | ||
|
Page:
1
|
Go to Top |

