0

I hope you can help me. I've done all steps like here "cakephp basic help to use cakedc search plugin" but the searcher doesn't anything.

My project is about one User's List and I want to filter for the fields 'apellidos' or 'dni'.

In my Controller I've the component declared and this:

public function index() {
    $this->Prg->commonProcess();
$this->paginate = array(
    'conditions' => $this->User->parseCriteria($this->passedArgs));
$this->set('users', $this->paginate());
    $this->User->recursive = 0;
    $this->User->order = 'User.cod_cliente';
    $this->User->conditions = 'User.nombre';
    if($this->Session->read('Auth.User.group_id')==5)
    {
        //$this->set('categorias', $this->User->find('all',array('fields'=>array('group_id','cod_cliente','nombre','apellidos','dni','id'))));
    }else
    {
        $this->User->conditions = array('User.cod_centro'=>$this->Session->read('Auth.User.cod_centro'));
        //$this->set('categorias', $this->User->find('all',array('fields'=>array('group_id','cod_cliente','nombre','apellidos','dni','id'),'conditions'=>array('User.cod_centro'=>$this->Session->read('Auth.User.cod_centro')))));
        }
    $this->set('categorias', $this->Paginator->paginate());
    $this->set('title_for_layout', __('Listado de usuarios')." - ".__('Administración'));
}

    public $presetVars = array(
array('field' => 'apellidos', 'type' => 'value'),
array('field' => 'dni', 'type' => 'value'),);

 public $actsAs = array('Containable','Search.Searchable','Acl' => array('type' => 'requester'));

public $filterArgs = array(
    array('name' => 'apellidos', 'type' => 'query', 'method' => 'filterApellidos'),
    array('name' => 'dni', 'type' => 'query', 'method' => 'filterDni'),
    );     

and here are also the functions:

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

     public function filterDni($data, $field = null) {
        if (empty($data['dni'])) {
            return array();
        }
        $dniField = '%' . $data['dni'] . '%';
        return array(
            'OR' => array(
                $this->alias . '.dni LIKE' => $dniField,
                ));
    }
    // 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);
     }

Finally, in the View I have this:

<div><?php
    echo $this->Form->create('Usuario', array(
        'url' => array_merge(array('action' => 'index'), $this->params['pass'])
        ));
    echo $this->Form->input('apellidos', array('div' => false, 'empty' => true)); // empty creates blank option.
    echo $this->Form->input('dni', array('div' => false, 'empty' => true));
    echo $this->Form->submit(__('Search', true), array('div' => false));
    echo $this->Form->end();
?>
    </div>

Could you tell me what I'm doing wrong, please? Thanks a lot!!

Belén

Community
  • 1
  • 1
  • 1
    Could you elaborate a bit on what the Search plugin isn't doing right? Do you get an error, does it never return any results or only unfiltered results? We could be of better help if we know what's going wrong. – Oldskool Jun 09 '15 at 13:08
  • Sure, @oldskool. The plugin never returns any results; I write something in the search's fields, push the button and it seems to do something but really doesn't return nothing. Thanks! – Belén Solana Jun 09 '15 at 14:06

0 Answers0