【问题标题】:cakephp plugin search cakeDC usagecakephp 插件搜索 cakeDC 使用
【发布时间】:2012-09-25 03:26:53
【问题描述】:

我正在使用 cakeDC 的 2.0 版本的 cakephp 搜索插件(带有 cakephp 2.x)(https://github.com/CakeDC/search)。我需要在许多模型中进行搜索,但这些模型不相关。所以我创建了一个新模型(搜索)和一个控制器(搜索)。我收到了这个错误

“注意(8):间接修改重载属性SearchesController::$paginate无效[APP/Controller/SearchesController.php, line 17]”

型号:

App::uses('AppModel', 'Model');
class Search extends AppModel {
    public $actsAs = array('Search.Searchable');
    public $useTable = false;
    public $filterArgs = array(
        'terminada' => array(
            'type' => 'like',
            'field' => array(
                'Sludge.terminada',
                'SurfacesWater.terminada',
                'ResidualWater.termianda',
                'UndergroundWater.terminada',
                'PotableWater.terminada',
                'SpecifiedsResidualsWater.terminada'
            )
        ),
        'revisada' => array(
            'type' => 'like',
            'field' => array(
                'Sludge.revisada',
                'SurfacesWater.revisada',
                'ResidualWater.revisada',
                'UndergroundWater.revisada',
                'PotableWater.revisada',
                'SpecifiedsResidualsWater.revisada'
            )
        ),
        'eliminada' => array(
            'type' => 'like',
            'field' => array(
                'Sludge.eliminada',
                'SurfacesWater.eliminada',
                'ResidualWater.eliminada',
                'UndergroundWater.eliminada',
                'PotableWater.eliminada',
                'SpecifiedsResidualsWater.eliminada'
            )
        ),
    );
    public function orConditionsDates($data = array()) {
        $start = date('Y-m-d');
        $end = date('Y-m-d', strtotime('-1 month'));
        $cond = array(
            'OR' => array(
                $this->alias . '.monitoreofecha LIKE <=' => $end,
                $this->alias . '.monitoreofecha LIKE >=' => $start,
                ));

        return $cond;
    }
}

控制器:

App::uses('AppController', 'Controller');
class SearchesController extends AppController {
    public $components = array('Search.Prg');
    public $presetVars = true; // using the model configuration
    public function index() {
        $this->Prg->commonProcess();
        $this->paginate['conditions'] = $this->Search->parseCriteria($this->passedArgs);
        $this->set('searches', $this->paginate());
    }
}

视图与使用 bake 制作的任何索引相同 知道我的错误是什么吗? 谢谢大家!!

S.

【问题讨论】:

    标签: cakephp search plugins cakedc


    【解决方案1】:

    如果你这样做,你需要先在你的控制器中声明分页:

    public $paginate = array();
    

    或者直接在你的方法中初始化

     $this->paginate = array();
    

    【讨论】:

      【解决方案2】:

      尝试这样做: App::uses('AppController', 'Controller');

      class SearchesController extends AppController {
        public $components = array('Search.Prg');
      
        public $presetVars = true; // using the model configuration    
      
        public $paginate = array();
      
        public function index() {
      
          $this->Prg->commonProcess();
      
          $cond = $this->Search->parseCriteria($this->passedArgs);
      
          $this->set('searches', $this->paginate('Search', $cond));
        }
      }
      

      【讨论】:

      • 现在我有很多警告 array_keys() 期望参数 1 是数组,给定 null [CORE/Cake/Model/Datasource/DboSource.php,第 2296 行] 问题是 $this- >搜索->parseCriteria($this->passedArgs);返回一个空数组。
      • 你试过我现在的脑袋了吗? github.com/dereuromark/search 我想我解决了一些问题。
      • PS:哪里是一个值 NULL 而不是一个数组。有问题的根源。某些方法返回空的不是数组。如果你能帮我找到那个方法,我可以帮助修复它。不过,到目前为止从未遇到过这个问题。
      • 标记我有相同的结果 pr($cond) 结果是 Array ()。有菜单其他错误“array_keys() 期望参数 1 为数组,给定 [CORE/Cake/Model/Datasource/DboSource.php, line 2296]”为空。这是因为我的模型没有表格,我正在尝试从其他模块获取结果。
      • 是的,您需要在分页数组中使用包含:$this-&gt;paginate['contain'] = array(...),并且不要忘记包含必要的模型。
      猜你喜欢
      • 2014-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多