I've trying to use the CakePHP Search Plugin along with the Blog tutorial available in the Cookbook and even though I followed the instruction to the letter I Keep getting this error message :Warning (512): SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'parseCriteria' at line 1 .
This is what I've done:
Model:
class Post extends AppModel {
var $name = 'Post';
var $displayField = 'title';
public $filterArgs = array(
array('name' => 'title','type' => 'string'),
);
}
Controller:
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());
}
}
View:
<?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();
?>
Do you have any idea why this is happening? Am I missing something?
You're getting that error because you haven't attached the behavior to your Post model. At the top of your Post model add:
var $actsAs = array('Search.Searchable');
精彩评论