开发者

Cakephp paginator not going to first page after a form submit

Below I have pasted code snippets of a page where it displays cars by year and model. This list is paginated. For this example, imagine that you go to page 5 of the list displayed. At the bottom of the page, there is a form that lets you refine your search. When you fill in another year and model and push "Search", it reloads the page with a new list of cars and years. The issue is that when you submit the form and the page reloads, the displayed content is on page 5 of the new search. How do I get the form submit to show the new search at page 1. I think one possible cause is that the url has "../search/page:5" in it when you try to submit the form:

$paginator->options(array('url' =>  array($condition_string)));
echo $paginator->sort('Year', 'Car.year', array('url' => array('page' => 1)));
echo $paginator->sort('Model', 'Car.model', array('url' => array('page' => 1)));

//table code that displays years开发者_如何学运维 and models

echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));
echo $paginator->numbers();
echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));

//form that submits new search
echo $form->create('Car', array('action' => 'search'));
echo $form->input('model');
echo $form->input('year');
echo $form->end('Search');


try using the "url"-option of the form-helper, like:

<?= $form->create('Car',array('url' => '/.../search')) ?>

EDIT (quick n' dirty fix):

<form action=".../search" method="post">
<input type="text" name="data[Car][model]" />
<input type="text" name="data[Car][year]" />
<?=$form->end("Search")?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜