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.

Data Model Questions /

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

Page::get() just returns an dataList Object without data


Go to End


4 Posts   3768 Views

Avatar
CoodY

Community Member, 1 Post

25 May 2013 at 5:27am

Edited: 25/05/2013 5:28am

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!

Avatar
Craftnet

Community Member, 58 Posts

27 May 2013 at 10:33pm

BUMP

Anyone know, because I have the same problem?

Avatar
Devlin

Community Member, 344 Posts

27 May 2013 at 10:43pm

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

Avatar
Craftnet

Community Member, 58 Posts

27 May 2013 at 11:04pm

Yeah, sure :)
Thank for help

Sorry for my bad English