【发布时间】:2019-10-29 21:59:08
【问题描述】:
我有一个显示所有产品并且工作正常的索引视图,我想在顶部有一个搜索栏,用户可以通过关键字搜索。我的控制器如下所示:
class ProductsController extends AppController{
public function search(){
$this->loadModel('Item');
$this->view('index');
$keyword = $this->request->data['Item']['keywords'];
$this->Product->recursive = 0;
$this->paginate = array(
'conditions' => array('Item.is_deleted' => false, 'Item.name LIKE' => "%$keyword", 'Item.item_type_id' => 15)
);
$this->set('products', $this->Paginator->paginate());
$this->redirect(array('action' => 'index'));
}
}
显示项目是因为产品是一个项目,我有两个表,但这应该不是问题,我只想按关键字过滤。
这是索引视图:
<div class="products index">
<h2><?php echo __('Products'); ?></h2>
<?php echo $this->Form->create('Product', array('url' => 'search')) ?>
<fieldset>
<legend><?php echo __('Search Products') ?></legend>
<?php
echo $this->Form->input('Item.keywords');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')) ?>
//other stuff for index view
但即使我在提交表单时将此视图呈现在搜索控制器中,但我得到“在此服务器上找不到请求的地址'/WarehouseManagementApp/products/search'”。 所以也许我遗漏了一些东西,或者我应该以不同的方式实现它。
【问题讨论】: