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

The method 'getviewer' does not exist on 'PaginatedList'


Go to End


3 Posts   1951 Views

Avatar
merrick_sd

Community Member, 99 Posts

6 December 2012 at 1:39am

Edited: 06/12/2012 11:24pm

I want to be able to filter a paginated list based on passed params.
eg filter buy Area, category ..etc

http://dev.mydomain.co.uk/property
if i go directly to the page i do not get an error.

 class EstateCategoryPage_Controller extends Page_Controller {
static $allowed_actions = array(
		'show','EstateItemList'
	);

//do i need a routes.yml file
public static $url_handlers = array(
	       'property//$Action/$ID/$EstateCategoryPageID' => 'EstateItemList'
	   );


function EstateItemList() {
	
	$Area = '%';
	$OfferStatus = 'FOR SALE';
	$ECatPageID = 30;
	
		
	/* test for retrival of QueryString 
	$CatPageID = Controller::curr()->getRequest()->param('EstateCategoryPageID');
	//$CatPageID = $this->request->param('EstateCategoryPageID');
	//print query string
	//print_r($CatPageID);   //yeap it works
	*/
	
	 $buildfilter = EstateItem::get()->filter(array('Area:PartialMatch'=> $Area,'Active' => 1,'OfferStatus' => $OfferStatus));
	 
	 //fixes the page in pagination
	  $PaginatedList = new PaginatedList($buildfilter,$this->request);
	  $PaginatedList->setPageLength(2);
	  $PaginatedList->setLimitItems(1);  
	   return $PaginatedList;	
	   
           }

//comment   i'm not actually doing any filtering yet from the passed params..baby steps!

....
}//end controller

If i go to the page and call a function to pass query string i get an error
http://dev.mydomain.co.uk/property//action/params/params/

eg: http://dev.mydomain.co.uk/property//EstateItemList/29/Offices/

error : The method 'getviewer' does not exist on 'PaginatedList'

i've looked at this ticket also
http://www.silverstripe.org/data-model-questions/show/11817

and tried

return $this->customise($PaginatedList)->renderWith('PropertyResults');

error : The method 'getviewer' does not exist on 'DataList'

return $this->customise($buildfilter)->renderWith('PropertyResults');

error : The method 'getviewer' does not exist on 'DataList'

// Please do not change the exception code number below.
660
661 throw new Exception("Object->__call(): the method '$method' does not exist on '$this->class'", 2175);

Line 661 in /home/hmyapp/public_html/framework/core/Object.php

Avatar
Willr

Forum Moderator, 5523 Posts

8 December 2012 at 4:47pm

You're trying to render a list directly using /EstateItemList/ in the browser which rather than returning an HTML template you've got it returning a List.

You should name your action and method *differently* or render the list into some template instead of returning it.

static $allowed_actions = array(
'show','list'
);

In your EstateCategoryPage_list.ss template then you would use <% loop EstateItemList %>

Make sure in your template you don't simply chuck $EstateItemList in as SilverStripe knows it's a list but not how you want to display it. You need to use <% loop %> to iterate over it.

Avatar
merrick_sd

Community Member, 99 Posts

11 December 2012 at 12:22am

Edited: 21/12/2012 11:27pm

many thanks that worked.

http://mydomain.com/property//list/29/Swansea/tolet

eg:
http://mydomain.com/property//$Action/$EstateCategoryPageID/$Area/$OfferStatus

http://doc.silverstripe.org/framework/en/topics/controller

I have
mysite > routes.yml
---
Name: myroutes
After: framework/routes#coreroutes
---
Director:
rules:
'property//$Action/$EstateCategoryPageID/$Area/$OfferStatus': 'EstateCategoryPage_Controller'

but this results in a error
[User Warning] popCurrent called on ModelAsController controller, but it wasn't at the top of the stack

basically i want to access more that the standard 2params of ID/OtherID
how i can use more than 2 params

for example: mydomain.com/mypage/myaction/PrmOne/PrmTwo/PrmThree

I can get my app to work by doing

mydomain.com/mypage/myaction?ECPID=whatevervalue&Area=whatevervalue&OfferStatus=whatevervalue