21309 Posts in 5738 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1707 Views |
-
[resolved] issues adding image upload field to cms

28 June 2010 at 12:04pm Last edited: 28 June 2010 12:28pm
See EDIT below:
Hello and thanks in advance for any help.
Using this tutorial:
http://doc.silverstripe.org/tutorial:2-extending-a-basic-siteI'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 errorThe 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.bEDIT:
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 {
}
?> -
Re: [resolved] issues adding image upload field to cms

28 June 2010 at 12:27pm
Images need to be in the $has_one array, not in the $db:
public static $db = array(
'Quotes_Author' => 'Text'
);public static $has_one= array(
'Quotes_Image' => 'Image'
);I think this is because an image is not just another field or variable in the database, but a whole object that needs to be pointed to.
Everything else looks good in your code.
-
Re: [resolved] issues adding image upload field to cms

28 June 2010 at 12:30pm
Thanks ampedup!
Chris.b
| 1707 Views | ||
|
Page:
1
|
Go to Top |


