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.

Data Model Questions /

[SOLVED] get and get_one - Do they work on DataObjects?


Reply


5 Posts   2493 Views

Avatar
Double-A-Ron

Community Member, 604 Posts

23 July 2009 at 5:17pm

Edited: 24/07/2009 11:31am

Hiya,

I'm sure the above is a stupid question. Of course these methods should work, in fact I'm sure this was working an hour ago.

I made a Testimonial class, extending DataObject. I also made a TestimonialPage extending Page where these are stored in a dataobject_manager grid.

I have added a simple method to Page.php controller so that all pages that extend page, have access to this:

public function getTestimonials() {
   return DataObject::get_one("Testimonial");
}   

That's it. I do a <% control getTestimonials %> on my template and all I get is a blank page. If I comment out the return above, all is OK (except no data of course). No errors, even in Dev mode.

Any thoughts?

Cheers
Aaron

Avatar
Willr

Forum Moderator, 5513 Posts

23 July 2009 at 5:42pm

watch out for your use of get in method names. Its not a protected keyword as such but it can cause odditites like this. If you have public function getTestimonials() then in the template you would do <% control Testimonials %> (dropping the get)

Avatar
Double-A-Ron

Community Member, 604 Posts

24 July 2009 at 9:13am

Edited: 24/07/2009 9:48am

Thanks for the heads-up Will. But that doesn't seem to be the problem.

I changed the method name to "bollocks" as a test and the same behavior occurs.

I did add an error_reporting line to the method however and got this:

Notice: Undefined index: Testimonial in /var/www/virtual/site/sapphire/core/ClassInfo.php on line 79

Warning: ClassInfo::dataClassesFor() no parents for Testimonial in /var/www/virtual/site/sapphire/core/ClassInfo.php on line 79

Warning: Invalid argument supplied for foreach() in /var/www/virtual/site/sapphire/core/ClassInfo.php on line 80

Fatal error: DataObjects have been requested before the manifest is loaded. Please ensure you are not querying the database in _config.php. in /var/www/virtual/site/sapphire/core/model/DataObject.php on line 2254

Any ideas. I get the feeling that this has something to do with Testimonial being used by the DataObjectManager. I notice that if I remove SortableDataObject::add_sortable_class('Testimonial'); from /mysite/_config.php, the first Notice above is repeated many times over.

Cheers
Aaron

Avatar
Double-A-Ron

Community Member, 604 Posts

24 July 2009 at 9:16am

Note that I am pretty much using this exact code here for the Testimonial and TestimonialPage classes:

http://doc.silverstripe.com/doku.php?id=modules:dataobjectmanager

Cheers
Aaron

Avatar
Double-A-Ron

Community Member, 604 Posts

24 July 2009 at 11:31am

Cancel that - I totally re-wrote the code and the issues went away:

http://www.silverstripe.org/dataobjectmanager-module-forum/show/265379?showPost=265382

Cheers
Aaron