Reputation: 453
I am using Cakephp 1.2. I should be able to sort by A-Z or Z-A with the paginate. However, I got this error below. No much information found in the other resources. please help.
Notice (8): Undefined variable: paginator [APP/views/elements/products.ctp, line 25] Fatal error: Call to a member function sort() on a non-object in /Applications/MAMP/htdocs/development03/app/views/elements/products.ctp on line 25
Controller
var $helpers = array('Html','Form','Ajax','Javascript', 'Text');
// Pagination
var $paginate = array('limit' => 8, 'page' => 1,'order'=>array('Product.name' => 'asc'));
function lists() {
$categories = $this->Category->find('all', array('order' => 'Category.id ASC' ));
$categories = $this->Category->buildCategories($categories, $this->passedArgs['c']);
$children_ids = $this->Category->getChildCategories($categories, $this->passedArgs['c'], true);
$allCatIds = array_merge(array($this->passedArgs['c']), $children_ids);
//return lists
return $this->Product->lists($allCatIds);
}
Element
<?php
$products = $this->requestAction("/products/lists/c:$catId/");
?>
<?php echo $paginator->sort('Name', 'name', array('title' => 'Sorting Title Alphabetically','class' => 'normalTip')); ?>
<?php foreach ($products as $product): ?>
...
<?php endforeach; ?>
Upvotes: 0
Views: 760
Reputation: 5464
To use the paginator class in your element, you must have to include the helper class in your controller. So your controller's code will looks like :
var $helpers = array('Html','Form','Ajax','Javascript', 'Text', 'Paginator');
More Explanation: "Fatal error: Call to a member function sort() on a non-object" comes when you are trying to access the method through an object which never been instantiated by any class. So your application must know which kind of object it is.
Kindly ask if it not worked.
Upvotes: 1
Reputation: 4011
It sounds like $paginator isn't set to anything.
If you put this code in your view, does it say $paginator is NULL?
var_dump($paginator);
It's hard to say from the code provided, but I assume you either
Upvotes: 0