Jump to:

5540 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » DataObject::get() on custom class

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

Page: 1
Go to End
Author Topic: 665 Views
  • nekranox
    Avatar
    Community Member
    31 Posts

    DataObject::get() on custom class Link to this post

    Hey guys,

    We've created a class which extends page called DetailPropertyPage. It just has loads of extra frields and some one-to-many relationships to Images and DataObjects.

    I'm writting a custom search function at the moment to return matching DataObjects.

    Here is my code:

    $properties = DataObject::get('DetailPropertyPage', $queryString, '`DetailPropertyPage`.`Price` ASC', '', '0, 30');

    I know that $queryString is correct because if I paste it into phpMyAdmin then I get results but it always turns up NULL in SilverStripe. Am I using the wrong caller class?

    Just in case it is useful, heres the typical contents for $queryString:

    `DetailPropertyPage`.`Status`='S' and `DetailPropertyPage`.`PropertyType`='Terraced' and `DetailPropertyPage`.`Bedrooms`>=1 and `DetailPropertyPage`.`Price`>=50000 and `DetailPropertyPage`.`Price`<=150000

    Thanks,

    Robbie

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: DataObject::get() on custom class Link to this post

    Using table names directly in the DataObject get is a little tricky as the table name for pages will actually be TableName_Live rather than TableName when viewing the published site. See https://github.com/silverstripe/silverstripe-forum/blob/master/code/ForumHolder.php#L345 for an example of the logic you need to include to get the right table for the query.

    PROTIP you can use ?showqueries=1 to see the SQL queries SilverStripe is running. Use that to grab the SQL query running and double check that.

    665 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.