我试图使用CakePHP搜索插件以及Cookbook中提供的博客教程,即使我按照说明继续收到此错误消息:警告(512):SQL错误:1064:您有错误在你的SQL语法中; 检查与MySQL服务器版本对应的手册,以便在第1行的'parseCriteria'附近使用正确的语法.
这就是我所做的:
模型:
class Post extends AppModel {
var $name = 'Post';
var $displayField = 'title';
public $filterArgs = array(
array('name' => 'title','type' => 'string'),
);
}
Run Code Online (Sandbox Code Playgroud)
控制器:
class PostsController extends AppController {
var $name = 'Posts';
public $components = array('Search.Prg');
public $presetVars = array(
array('field' => 'title', 'type' => 'value'),
);
function beforeFilter() {
parent::beforeFilter();
}
public function index() {
$this->Prg->commonProcess();
$this->paginate = array(
'conditions' => $this->Post->parseCriteria($this->passedArgs));
$this->paginate = array('limit' => 15);
$this->set('posts', $this->paginate());
}
}
Run Code Online (Sandbox Code Playgroud)
视图:
<?php
echo $this->Form->create('Post', array(
'url' => array_merge(array('action' => 'index'), $this->params['pass'])
));
echo $this->Form->input('title', array('div' => false, 'empty' => true));
echo $this->Form->submit(__('Search', true), array('div' => false));
echo $this->Form->end();
?>
Run Code Online (Sandbox Code Playgroud)
你知道为什么会这样吗?我错过了什么吗?
小智 5
您收到该错误是因为您尚未将该行为附加到Post模型.在Post模型的顶部添加:
var $actsAs = array('Search.Searchable');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1690 次 |
| 最近记录: |