1

Cakephp ページネーションのレンダリングの問題。私はcakephp 2.0.6を使用しています。他のアクションからページをレンダリングしようとすると、うまくいきます。しかし、次のページに移動しようとすると、問題が発生します

私は次の機能を持っています

   public function admin_index() 
   {
       //Function listing 
   }

すべてのタイプのユーザー (サポート、従業員など) に同じ機能が必要です。そこで、次のように setAction メソッドを使用しました

public function support_index() 
   {
        $this->setAction('admin_index');
        $this->render('admin_index');
   }

そして、私のページネーションコードは次のとおりです:

    echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));

    echo $this->Paginator->numbers(array('separator' => ''));

    echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));

しかし、次のページに移動しようとすると、次のような URL

http://www.example.com/support/users/admin_index/page:2
http://www.example.com/employee/users/admin_index/page:2

ただし、次の出力が必要です。

http://www.example.com/support/users/index/page:2
http://www.example.com/employee/users/index/page:2

問題は $this->setAction('admin_index'); です。私は思う..誰もが感謝するのに役立ちます

4

2 に答える 2

1

次のファイルに変更を加えましたlib/Cake/Controller/Controller.php

setAction メソッドで行われた変更により、現在はうまく機能しています。特に問題は2.0.6にあります

public function setAction($action) {
    $this->request->params['action'] = $action; //Commented this Line 
    $this->view = $action; //Commented this Line


    $this->request->action = $action; // Added this Line
    $args = func_get_args();
    unset($args[0]);
    return call_user_func_array(array(&$this, $action), $args);

}
于 2012-08-29T11:39:12.180 に答える
0

setAction

あるアクションを別のアクションに内部的にリダイレクトします。Controller::redirect(); とは異なり、別の HTTP リクエストを実行しません。

リダイレクトは別の用語です。実際に別のアクションにリダイレクトすると、自動的にそのアクションになるため、ページネーションは URL を変更しません。

setAction を使用する代わりに、次のコードを使用できます。

public function admin_index() 
{
    $this->set('data',$this->__paginatedata());

}

function __paginatedata(){
    $this->paginate = array('limit'=>5);
    $this->Model->recursive = 0;
    return $this->paginate();
}

public function support_index() 
{
    $this->set('data',$this->__paginatedata());
    $this->render('admin_index');
}
于 2012-08-29T05:33:13.310 に答える