CakePHP搜索插件的问题

时间:2011-05-16 17:12:17

标签: cakephp

我尝试使用CakePHP Search Plugin以及Cookbook中提供的Blog tutorial,即使我按照说明继续收到此错误消息:警告(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'),
    );
}

控制器:

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());
   }

}

查看:

<?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();
?>

你知道为什么会这样吗?我错过了什么吗?

1 个答案:

答案 0 :(得分:5)

您收到该错误是因为您尚未将该行为附加到Post模型。在Post模型的顶部添加:

var $actsAs = array('Search.Searchable');