PHP
1//PagingSupportComponent.php 2 3namespace App\Controller\Component; 4use Cake\Controller\Component; 5use Cake\Core\Configure; 6 7/** 8 * 既存のページング機能をサポートするコンポーネント 9 */ 10 11class PagingSupportComponent extends Component { 12 13 var $_controller = null; 14 var $_sessionName = ''; 15 16 function startup( & $controller ) { 17 $this->_controller = $controller; 18 $this->_sessionName = $this->_getSessionName( $controller->params ); 19 } 20 21 /** 22 * controller->data の値の引き継ぎを行う 23 */ 24 function inheritPostData(){ 25 26 if( !empty( $this->_controller->data ) ){ 27 $this->request->session()->write( $this->_sessionName, $this->_controller->data ); 28 } 29 elseif( !empty( $this->_controller->params['named']['page'] ) && $this->request->session()->check( $this->_sessionName ) ){ 30 $this->_controller->data = $this->request->session()->read( $this->_sessionName ); 31 } 32 else{ 33 $this->request->session()->delete( $this->_sessionName ); 34 } 35 } 36 37 /** 38 * 現在引き継がれているPostDataを取得 39 * @param $params = array( 'controller' => ..., 'action' => ... ) 40 * @return array 41 */ 42 function getInheritPostdata( $params ){ 43 if( $this->request->session()->check( $this->_getSessionName( $params ) ) ){ 44 return $this->request->session()->read( $this->_getSessionName( $params ) ); 45 } 46 else{ 47 return null; 48 } 49 } 50 51 /** 52 * SESSIONに使用する名前を取得 53 */ 54 private function _getSessionName( $params ){ 55 return 'pagingSupport_' . $params['controller'] . $params['action']; 56 } 57}
PHP
1//HogesController.php 2 3$this->PagingSupport->inheritPostData(); //$this->dataの値の引き継ぎが行われる 4$conditions = array(); 5if( !empty( $this->request->data ) ){ 6 $conditions = $this->request->params['paging'] ; //検索フォームの入力値から conditions を取得 7 } 8 9$this->set('hoges', $this->paginate( 'Hoges', $conditions) );
######問題
$conditions = $this->request->params['paging'] ;
$conditionsに入れる内容が間違っていると思っています。
ただ、何を入れたらいいかわからず、困っています。
######補足
テーブル検索後にページングがうまく動かないため
cakephpのページング時の検索条件の引き継ぎ
こちらを参考にしました。
内容が少し古かったので
$this->Session
↓
$this->request->session()
に変更しています。
回答1件
あなたの回答
tips
プレビュー