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 /

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


Go to End
Reply


4 Posts   941 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, 228 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