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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

DataObject returns 'Not Found' when trying to save


Go to End


6 Posts   816 Views

Avatar
Vix

Community Member, 60 Posts

7 January 2015 at 4:32pm

Edited: 07/01/2015 4:41pm

I have a 3.1 site that for the last year has been fine and now has started throwing a 'Not found' error when I try to save a particular Dataobject through Model Admin.

To try to resolve this I have updated the site to 3.1.8 this morning,but still no luck.

The Dataobject's code is:

class Instructor extends DataObject {
	public static $db = array (
			'Name' => 'Text',
			'Initials' => 'Text',
			'Qualifications' => 'Text',
			'Background' => 'HTMLText',
			'Active' => 'Int',
			'SortOrder' => 'Int'
	);
	
	public static $has_one = array(
			'Image' => 'Image'
	);	
	
	public static $summary_fields = array(
			'Name' => 'Name',
			'ActiveNice' => 'Show on website?'
	);	
	 
	 
    public function ActiveNice() { 
      return $this->Active ? 'Yes' : 'No'; 
   } 
   
   function getCMSFields(){
		$fields = new FieldList();
		$fields->push(new CheckboxField('Active', 'Show this instructor on website?'));
		$fields->push(new TextField('Name'));
		$fields->push(new TextField('Initials', 'Initials for timetable page'));
		$fields->push(new TextField('Qualifications'));
		$fields->push(new UploadField('Image', 'Image'));
		$fields->push(new HTMLEditorField('Background', 'Experience & Background'));		
		return $fields;
	}
	
}

I have also tried removing the image field altogether but that has not worked either.

Hoping someone has come across this before and can help me out.

/****UPDATE****/
I have just tried attaching the dataobject to a page with a gridfield and they work fine. Not sure what is going on

Avatar
nzstephenf

Community Member, 63 Posts

7 January 2015 at 7:40pm

Maybe as a 'first things first' check off the list, change your statics from 'public static' to 'private static'.
I was about to say, maybe ActiveNice could be the culprit! But notice you have a function going which connects with this.

Try making your getCMSFields() a public function.

If none of this helps, possibly change how your form is put together by going:

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

$uploadField = new UploadField("Image", "Image upload field heading");
$uploadField->setFolderName("optional-value");

 $fields->addFieldToTab("Root.Main", new TextField("Example", "Example Title goes here");
 $fields->addFieldToTab("Root.Main", $uploadField);

 return $fields;
}

Let me know how you go!

Stephen

Avatar
nzstephenf

Community Member, 63 Posts

7 January 2015 at 7:41pm

Also, how is your ModelAdmin for this setup?
The problem could lie with the Model Admin.

Avatar
Vix

Community Member, 60 Posts

7 January 2015 at 7:57pm

Hi Stephen
Thanks for your suggestions, but unfortunately they have not worked. It is odd how if I attach them with a gridfield to a page in the cms they work fine.

Originally with the ModelAdmin I had them as a part of a few different managed_models, so I tried giving it its own separate ModelAdmin with the following code:

class InstructorAdmin extends ModelAdmin {
	private static $managed_models = array('Instructor');
	
	private static $url_segment = 'teachers';
	
	private static $menu_title = 'Instructors';
	
	private static $menu_icon = 'themes/purple/images/cms-icons/instructor.png';
	
}

But that has not worked either.

Avatar
nzstephenf

Community Member, 63 Posts

7 January 2015 at 8:19pm

Do you have any other things within your Instructor class?
Just trying to see what could be causing you some grief.

Avatar
Vix

Community Member, 60 Posts

7 January 2015 at 8:37pm

What I have posted is the entire class, not much to it.

I have just renamed the class to 'Teacher' and the ModelAdmin to show 'Teacher' and it works fine... Changed nothing about it except changing the name of the file and the class, so stumped what it does not like about the Instructor one.