【问题标题】:Cakephp paginator not going to first page after a form submit提交表单后,Cakephp 分页器不会进入第一页
【发布时间】:2010-07-10 22:19:59
【问题描述】:

下面我粘贴了一个页面的代码 sn-ps,它按年份和型号显示汽车。这个列表是分页的。对于此示例,假设您转到所显示列表的第 5 页。在页面底部,有一个表单可让您优化搜索。当您填写另一个年份和型号并按下“搜索”时,它会重新加载页面,其中包含新的汽车和年份列表。问题是当您提交表单并重新加载页面时,显示的内容在新搜索的第 5 页上。如何让表单提交以在第 1 页显示新搜索。我认为一个可能的原因是当您尝试提交表单时,url 中包含“../search/page:5”:

$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');

【问题讨论】:

    标签: cakephp forms pagination submit


    【解决方案1】:

    尝试使用表单助手的“url”选项,例如:

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

    编辑(快速修复):

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

    【讨论】:

    • 这似乎没有做任何事情。即使它在第 5 页加载了新搜索,url 仍然保持不变。也许我需要告诉 $paginator->sort 对页面做一些事情?
    猜你喜欢
    • 1970-01-01
    • 2016-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多