简体   繁体   English

cakephp 1.2 requestAction分页

[英]cakephp 1.2 requestAction pagination

I am using Cakephp 1.2. 我正在使用Cakephp 1.2。 I should be able to sort by AZ or ZA with the paginate. 我应该可以用分页符按AZ或ZA排序。 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 通知(8):未定义的变量:分页器[APP / views / elements / products.ctp,第25行]致命错误:在/ Applications / MAMP / htdocs / development03 / app中的非对象上调用成员函数sort()第25行的/views/elements/products.ctp

Controller 控制者

var $helpers = array('Html','Form','Ajax','Javascript', 'Text');

// Pagination 
var $paginate = array('limit' => 8, 'page' => 1,'order'=>array('Product.name' => 'asc')); 

function lists() { 函数list(){

    $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; ?>

To use the paginator class in your element, you must have to include the helper class in your controller. 要在元素中使用paginator类,必须在控制器中包括helper类。 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. 更多说明:当您尝试通过从未由任何类实例化的对象访问方法时,将出现“致命错误:在非对象上调用成员函数sort()”。 So your application must know which kind of object it is. 因此,您的应用程序必须知道它是哪种对象。

Kindly ask if it not worked. 请问它是否不起作用。

It sounds like $paginator isn't set to anything. 听起来$ paginator没有设置任何东西。

If you put this code in your view, does it say $paginator is NULL? 如果在您的视图中放置此代码,是否表示$ paginator为NULL?

var_dump($paginator);

It's hard to say from the code provided, but I assume you either 从提供的代码很难说,但我想你要么

  1. Aren't making $paginator available to your view in your controller 在控制器中无法将$ paginator提供给视图
  2. Are using the incorrect variable name altogether 完全使用了错误的变量名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM