Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [SOLVED] get and get_one - Do they work on DataObjects?

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

Page: 1
Go to End
Author Topic: 2324 Views
  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    [SOLVED] get and get_one - Do they work on DataObjects? Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: [SOLVED] get and get_one - Do they work on DataObjects? Link to this post

    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)

  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Re: [SOLVED] get and get_one - Do they work on DataObjects? Link to this post

    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

  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Re: [SOLVED] get and get_one - Do they work on DataObjects? Link to this post

    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

  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Re: [SOLVED] get and get_one - Do they work on DataObjects? Link to this post

    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

    2324 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.