我正在使用 cakephp 2.1 和 cakedc 搜索插件。
问题是我不能把它粘在一起。还得到:
Notice (8): Indirect modification of overloaded property ProjectsController::$paginate has no effect [APP\Controller\ProjectsController.php, line 48]
遵循 cakedc 教程,但缺少一些东西!简单的搜索不会过滤任何内容。
我想按名称字段过滤。
在我的项目模型上
public $actsAs = array('Search.Searchable');
var $name = 'Project';
public $filterArgs = array(
array('name' => 'name', 'type' => 'like'),
array('name' => 'filter', 'type' => 'query', 'method' => 'orConditions'),
);
public function orConditions($data = array()) {
$filter = $data['filter'];
$cond = array(
'OR' => array(
$this->alias . '.name LIKE' => '%' . $filter . '%',
//$this->alias . '.body LIKE' => '%' . $filter . '%',
));
return $cond;
}
在我的控制器中:
public $components = array('Search.Prg');
public $presetVars = array(
array('field' => 'name', 'type' => 'value')
);
索引函数更新为仅使用 index.ctp(无查找函数)
public function index() {
$this->Prg->commonProcess();
$this->Project->recursive = 0;
// next line causes
// Notice (8): Indirect modification of overloaded property ProjectsController::$paginate has no effect [APP\Controller\ProjectsController.php, line 48]
//$this->paginate['conditions'] = $this->Project->parseCriteria($this->passedArgs);
$this->set('projects', $this->paginate());
}
并将搜索表单添加到 view.ctp
echo $this->Form->create('Project', array('url' => array_merge(array('action' => 'index'), $this->params['pass'])));
echo $this->Form->input('name', array('div' => false));
echo $this->Form->submit(__('Search', true), array('div' => false));
echo $this->Form->end();
我知道这一定是我的一些明显错误,请多多包涵。任何人都可以帮忙吗?
非常感谢 !