See EDIT below:
Hello and thanks in advance for any help.
Using this tutorial:
http://doc.silverstripe.org/tutorial:2-extending-a-basic-site
I'm trying to add an image and a text field to my page controller, but to no avail.
Here is my code:
<?php
class CustomerQuotesPage extends Page {
static $db = array(
'Quotes_Author' => 'Text',
'Quotes_Image' => 'Image'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new TextField('Quotes_Author'), 'Content');
$fields->addFieldToTab("Root.Content.Images", new ImageField('Quotes_Image'));
return $fields;
}
}
class CustomerQuotesPage_Controller extends Page_Controller {
}
?>
This is the error I get after i /dev/build/
# Table CustomerQuotesPage: created
# Field CustomerQuotesPage.ID: created as int(11) not null auto_increment
# Field CustomerQuotesPage.Quotes_Author: created as mediumtext character set utf8 collate utf8_general_ci
Website Error
There has been an error
The website server has not been able to respond to your request.
This isn't the first time I've created a cms controller, but it's the first time I've tried to add an image field. When I remove the image field, everything works fine.
Any help is greatly appreciated.
Thanks!
Chris.b
EDIT:
Looks like I didn't follow the tutorial 100%. Note the image needs to use $has_one instead of $db.
Code should have looked like this:
<?php
class CustomerQuotesPage extends Page {
static $db = array(
'Quotes_Author' => 'Text'
);
static $has_one = array(
'Quotes_Image' => 'Image'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new TextField('Quotes_Author'), 'Content');
$fields->addFieldToTab("Root.Content.Images", new ImageField('Quotes_Image'));
return $fields;
}
}
class CustomerQuotesPage_Controller extends Page_Controller {
}
?>