1つのテキストボックス、2つのドロップダウン、およびラジオボタン(cakephp内)を備えた検索フォームが必要です。しかし、これはページ付けで行われます。検索とページ付けは別々に機能しますが、一緒には機能しません。フィルタ条件を選択して検索ボタンをクリックすると、1ページ目に結果が正常に表示されますが、いずれかのページネーションリンクをクリックすると、フィルタ条件が失われ、フィルタなしでページネーションデータが表示されます。どうすればこれを解決できますか?コントローラコード:
private function _index() {
$this->genre_list();
$this->language_list();
$conditions = array();
debug($this->postConditions($this->data)); die;
if (!empty($this->request->data['Artist'])) {
foreach ($this->request->data['Artist'] as $name => $record) {
if (isset($record) && !empty($record)) {
if ($name == 'name') {
$conditions = array(
$this->modelClass->User. 'User.name LIKE' => '%' . $record . '%',
);
} else {
$conditions[$this->modelClass . '.' . $name] = $record;
}
}
}
};
$this->paginate = array(
'contain' => array (
'User' => array(
'City',// => array('name'),
'State',// => array('name'),
'Country',// => array('name'),
),
'Genre',// => array('name'),
'Language',// => array('language'),
),
'limit' => 3,
'conditions' => $conditions
);
$data = $this->paginate($this->modelClass);
//~ debug($data);
$this->set(compact('data'));
}
見る:
<?php
echo $this->Form->create('Search', array(
'type' => 'file',
'inputDefaults' => array(
'format' => array(
'label', 'between', 'input', 'error', 'after'
)
),
'class' => 'form-horizontal'
));
echo $this->Form->input('Artist.name', array(
'div' => 'control-group',
'label' => array(
'class' => 'control-label',
'text' => 'Artist Name'
),
'between' => '<div class="controls">',
'after' => '</div>',
'placeholder' => 'Name',
'error' => array(
'attributes' => array(
'wrap' => 'div',
'style' => 'color:#B94A48'
)
)
));
echo $this->Form->input('Artist.genre_id', array(
'div' => 'control-group',
'empty' => 'All',
'label' => array(
'class' => 'control-label',
'text' => 'Genre'
),
'between' => '<div class="controls">',
'after' => '</div>',
'error' => array(
'attributes' => array(
'wrap' => 'div',
'style' => 'color:#B94A48'
)
)
));
echo $this->Form->input('Artist.language_id', array(
'div' => 'control-group',
'empty' => 'All',
'label' => array(
'class' => 'control-label',
'text' => 'Select Lanuage'
),
'between' => '<div class="controls">',
'after' => '</div>',
'error' => array(
'attributes' => array(
'wrap' => 'div',
'style' => 'color:#B94A48'
)
)
));
?>
<?php echo $this->element('pagination');
セッションで編集されたコード
private function _index() {
$this->genre_list();
$this->language_list();
$conditions = array();
//~ foreach($this->request->params['named'] as $key => $record) {
//~ debug($this->request->params['named']);
//~ $this->request->data['Search'][$key] = $record;
//~ }
if (!empty($this->request->params['named']['page'])) {
// use session data for conditions
$conditions = (array)$this->Session->read('_indexConditions');
} else {
// delete session data
$this->Session->delete('_indexConditions');
}
$conditions = array();
if (!empty($this->request->data)) {
// new search! use the data to make conditions,
// like you did, and save the conditions
//~ if (!empty($this->request->data['Artist'])) {
foreach ($this->request->data['Search'] as $name => $record) {
if (isset($record) && !empty($record)) {
if ($name == 'name') {
$conditions = array(
$this->modelClass->User. 'User.name LIKE' => '%' . $record . '%',
);
} else {
$conditions[$this->modelClass . '.' . $name] = $record;
}
}
}
//~ }
$this->Session->write('_indexConditions', $conditions);
}
$this->paginate = array(
'contain' => array (
'User' => array(
'City',
'State',
'Country',
),
'Genre',
'Language',
),
'limit' => 3,
'conditions' => $conditions
);
$data = $this->paginate('Artist');
$this->set(compact('data'));
}