Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS /

ImageField throwing page not found error


Reply


3 Posts   1193 Views

Avatar
Sherry

Community Member, 4 Posts

10 August 2010 at 7:20pm

I have launched about 5 or 6 SilverStripe installations, many of which use the imagefield following the example in tutorial 2: http://doc.silverstripe.org/tutorial:2-extending-a-basic-site. The sites I've launched using SS v2.3.x work fine, but with the last 2 sites, which use v2.4.1 the imagefields are not working for me.

I've tried several variations of code and all yield the same result in 2.4.1: The image field displays a page not found page using whatever template is set for the site. Specifically, the error is: Sorry, it seems you were trying to access a page that doesn't exist. Please check the spelling of the URL you were trying to access and try again.

I have had no luck determining the difference between my v2.3 sites where the image field works as expected and the v2.4.1 sites where it doesn't. Any assistance is appreciated.

The latest rendition of the code is:

<?php
class SalonPage extends Page {

   public static $db = array(
   );

static $has_one = array(
'Photo' => 'Image'
);

function getCMSFields() {
    $fields = parent::getCMSFields();
    $picField = new ImageField('Photo');
    $fields->addFieldToTab("Root.Content.Images", $picField);      
   
    return $fields;
}

}
class SalonPage_Controller extends Page_Controller {

   public function init() {
      parent::init();
   }
}
?>

Avatar
swaiba

Forum Moderator, 1798 Posts

10 August 2010 at 8:04pm

For a Page (public facing) I believe the only route is something like this...

$fields->replaceField('Photo',new SimpleImageField('Photo'));

but within the CMS I don't ever need to do anything in order to get my images to appear as I use ModelAdmin and the scaffolding works just fine.

Sorry I can't be more help...

Avatar
Sherry

Community Member, 4 Posts

11 August 2010 at 4:34am

Thanks for the reply. Unfortunately, that code variation threw the same error.

I've added a work around that just creates another HTMLEditorField and the image is added there:
static $db = array(
      'PageTitlePic' => 'HTMLText'
);

function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab("Root.Content.Main", new HTMLEditorField('PageTitlePic', 'Page Title'),'Content');

return $fields;
}