cakephp使用cakedc搜索插件的基本帮助 [英] cakephp basic help to use cakedc search plugin

查看:83
本文介绍了cakephp使用cakedc搜索插件的基本帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用cakephp 2.1和cakedc搜索插件。

问题是我无法将其粘合在一起。还得到:

I'm using cakephp 2.1 and cakedc search plugin.
The thing is I can't glue it together. Also got:

Notice (8): Indirect modification of overloaded property ProjectsController::$paginate has no effect [APP\Controller\ProjectsController.php, line 48]

cakedc后续教程,但缺少内容!简单的搜索就不会过滤任何内容。

我想按名称字段进行过滤。

Followed cakedc tutorial but something's missing! Simple search just won't filter anything.
I want to filter by name field.

在我的项目模型上

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(无查找功能)

index function updated to use index.ctp only (no find function)

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

and added search form to 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();

我知道这一定是我明显的错误,请多多包涵。
谁能帮忙吗?

I know this must be some obvious error on my part, please bear with me. Can anyone help?

非常感谢!

推荐答案

很高兴让人们知道我找到了使用cakedc搜索插件的方式。

I'm glad to let people know I found my way to use cakedc search plugin.

首先,我必须紧紧遵循1.3的本教程(起初,我认为它不会对2.1有用,但它的作用就像魅力一样。)

First I had to closely follow this tutorial for 1.3 (at first I thought it won't do for 2.1, but it works like charm.)

http://www.youtube.com/watch?v = FAVuLXFVaCw

并从cakedc
http://cakedc.com/eng/downloads/view/cakephp_search_plugin

可以理解视频教程。 (尝试按照自述文件说明运行它,但收到错误致命错误:在第83行的C:wamp\www\search\webroot\index.php中找不到类'Dispatcher',因此
选择了只需获取代码片段并使它们在2.1中工作)

AND downloaded 1.3 sample code from cakedc http://cakedc.com/eng/downloads/view/cakephp_search_plugin
to make sense of video tutorial. (tried to run it following readme instructions but got error Fatal error: Class 'Dispatcher' not found in C:\wamp\www\search\webroot\index.php on line 83 so chose to just get code snippets and have them work in 2.1)

返回我的项目:

1.-从cakedc搜索版本2.1 https://github.com/CakeDC/search

文件CakeDC-search-2.1-0-g834f79f.zip。

1.- Downloaded search version 2.1 from cakedc https://github.com/CakeDC/search,
file CakeDC-search-2.1-0-g834f79f.zip.

2。-将所有文件放在/ plugins / Search /文件夹中

2.- Placed all files on /plugins/Search/ folder

3.-已添加

CakePlugin::load('Search');  

到/Config/bootstrap.php的底部

to the bottom of /Config/bootstrap.php

4.-在我的控制器上,声明了组件和预置变量(我使用的是名为name的字段)

4.- On my controller, declared the component and presetVars (I'm using a field called name)

public $components = array('Search.Prg');
public $presetVars = array(
    array('field' => 'name', 'type' => 'value'),
    array('field' => 'pr_status', 'type' => 'value'),
);

5.-并更新了我的索引函数:

5.- and updated my index function:

public function index() {
    $this->Prg->commonProcess();
    $this->paginate = array(
        'conditions' => $this->Project->parseCriteria($this->passedArgs));
    $this->set('projects', $this->paginate());
}

6.-在我的模型上,添加

6.- on my model, added

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

        public $filterArgs = array(
            array('name' => 'name', 'type' => 'query', 'method' => 'filterName'),
            array('name' => 'pr_status', 'type' => 'value'),
        );

        public function filterName($data, $field = null) {
            if (empty($data['name'])) {
                return array();
            }
            $nameField = '%' . $data['name'] . '%';
            return array(
                'OR' => array(
                    $this->alias . '.name LIKE' => $nameField,
                    ));
        }

        // Built a list of search options (unless you have this list somewhere else)
        public function __construct($id = false, $table = null, $ds = null) {
        $this->statuses = array(
                    '' => __('All', true),
                     0 => __('Bid', true),
                     1 => __('Cancelled', true),
                    2 => __('Approved', true),
                    3 => __('On Setup', true),
                    4 => __('Field', true),
                    5 => __('Closed', true),
                    6 => __('Other', true));
         parent::__construct($id, $table, $ds);
         }

7。-最后,在index.ctp上的右上方创建了搜索表单表格标记

7.- Lastly, created the search form on index.ctp, right above the table tag

    <div><?php
        echo $this->Form->create('Project', array(
            'url' => array_merge(array('action' => 'index'), $this->params['pass'])
            ));
        echo $this->Form->input('name', array('div' => false, 'empty' => true)); // empty creates blank option.
                echo $this->Form->input('pr_status', array('label' => 'Status', 'options' => $statuses));
        echo $this->Form->submit(__('Search', true), array('div' => false));
        echo $this->Form->end();
    ?>
        </div>

我还学会了不放弃1.3教程和文档,即使我使用的是2.1。
下一步是按日期和更好的搜索表单进行筛选。

I also learned not to discard 1.3 tutorials and documentation even though i'm using 2.1. Next step is to filter by dates and a nicer search form.

祝大家好运。

卡洛斯

这篇关于cakephp使用cakedc搜索插件的基本帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆