Jump to:

3433 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Page::get() just returns an dataList Object without data

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

Page: 1
Go to End
Author Topic: 631 Views
  • CoodY
    Avatar
    Community Member
    1 Post

    Page::get() just returns an dataList Object without data Link to this post

    I am new to Silverstripe and have to edit some basics. But there is one problem I've got with the framework.
    Inside the Page_Controller I added a pubic function search() where I want to retrieve all pages with a specific keyword in its title.
    Anyway. I cannot get even a single page with this:

          public function siteSearch() {
          //$q = Convert::raw2sql($_POST['q']);
          $results = Page::get()->filter(array('ID' => '6'));

          echo '<pre>';
          print_r( $results );
          echo '</pre>';
          die();

    All I get is an "empty" DataList Object. Not the data itself. What I thought is Page::get() will return all pages, but it doesn't. I get this instead;

    DataList Object
    (
    [dataClass:protected] => Page
    [dataQuery:protected] => DataQuery Object
    (
    [dataClass:protected] => Page
    [query:protected] => SQLQuery Object
    (
    [select:protected] => Array
    (
    )

    [from:protected] => Array
    (
    [SiteTree] => "SiteTree"
    )

    [where:protected] => Array
    (
    )

    [orderby:protected] => Array
    (
    ["Sort"] => ASC
    )

    [groupby:protected] => Array
    (
    )

    [having:protected] => Array
    (
    )

    [limit:protected] => Array
    (
    )

    [distinct:protected] => 1
    [delete:protected] =>
    [connective:protected] => AND
    [replacementsOld:protected] => Array
    (
    )

    [replacementsNew:protected] => Array
    (
    )

    )

    [collidingFields:protected] => Array
    (
    )

    [queriedColumns:DataQuery:private] =>
    [queryFinalised:DataQuery:private] =>
    [querySubclasses:protected] => 1
    [filterByClassName:protected] => 1
    [queryParams:DataQuery:private] => Array
    (
    [Versioned.mode] => stage
    [Versioned.stage] => Live
    )

    )

    [model:protected] => DataModel Object
    (
    [customDataLists:protected] => Array
    (
    )

    )

    [inAlterDataQueryCall:protected] =>
    [failover:protected] =>
    [customisedObject:protected] =>
    [objCache:ViewableData:private] => Array
    (
    )

    [class] => DataList
    [_config_forclass:Object:private] =>
    [extension_instances:protected] => Array
    (
    )

    )

    Hope you get where my problem is :-D Many thanks all!

  • Craftnet
    Avatar
    Community Member
    58 Posts

    Re: Page::get() just returns an dataList Object without data Link to this post

    BUMP

    Anyone know, because I have the same problem?

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: Page::get() just returns an dataList Object without data Link to this post

    That's perfectly fine. Silverstripe 3 works with lazy loading, that means the query isn't get executed "until you iterate on the result with a foreach() or <% loop %>".

    $results = Page::get(); // returns empty DataList

    // sql query get executed
    foreach($results AS $result) {
    print_r($result); // your result
    }

    @see
    http://doc.silverstripe.org/framework/en/3.1/topics/datamodel

  • Craftnet
    Avatar
    Community Member
    58 Posts

    Re: Page::get() just returns an dataList Object without data Link to this post

    Yeah, sure
    Thank for help

    Sorry for my bad English

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