1

I'm using the 2.0 version of cakephp search plugins by cakeDC (with cakephp 2.x)(https://github.com/CakeDC/search) . I'm need search in many models but thats models aren't related. So i create a new model (search) and a controller (searches) . I got this error

"Notice (8): Indirect modification of overloaded property SearchesController::$paginate has no effect [APP/Controller/SearchesController.php, line 17]"

Model:

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

Controller:

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

The view is the same of any index make with bake Any idea how what is my mistake? Thanks for all!!

S.

ssalvatori
  • 100
  • 1
  • 1
  • 7

2 Answers2

1

if you do it this way you need to declare paginate first in your controller:

public $paginate = array();

or initialize it in your method directly

 $this->paginate = array();
mark
  • 21,691
  • 3
  • 49
  • 71
0

Try do it this way: 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));
  }
}
Greg Motyl
  • 2,478
  • 17
  • 31
  • Now i have a lot of warnings array_keys() expects parameter 1 to be array, null given [CORE/Cake/Model/Datasource/DboSource.php, line 2296] The problem is that $this->Search->parseCriteria($this->passedArgs); return an empty array . – ssalvatori Sep 25 '12 at 11:40
  • did you try my current head? https://github.com/dereuromark/search i think i fixed a few things. – mark Sep 25 '12 at 11:54
  • PS: where exactly is a value NULL instead of an array. there is the source of the problem. some method returns not array for empty. if you can help me find that method, I can help fixing it. never had this issue so far, though. – mark Sep 25 '12 at 12:10
  • mark i have the same result pr($cond) the result is Array (). There are menu others error "array_keys() expects parameter 1 to be array, null given [CORE/Cake/Model/Datasource/DboSource.php, line 2296]" . This that the problem is because my model doesn't have table and i i'm trying to get result from others modules. – ssalvatori Sep 25 '12 at 23:00
  • yeah, you need to use contain in your paginate array: `$this->paginate['contain'] = array(...)` and dont forget to include the models necessary. – mark Sep 25 '12 at 23:44