Wednesday, September 25, 2013

Re: Records search using CakeDC/search



On Monday, 15 April 2013 19:09:01 UTC-4, cricket wrote:
You can get rid of that notice by declaring the $paginate array as a class var:

public $paginate = array();
public $components = ...


On Mon, Apr 15, 2013 at 8:22 AM, Muhammad Asyraf <asyra...@gmail.com> wrote:
I've made the amendment to the code but still the result are same. no search result produced and i notice there is warning on top of the page say:

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

where the code that caused the notice to appear is:

 $this->paginate['conditions'] = $this->Patient->parseCriteria($this->passedArgs);

is there any other codes that i've missed? Thanks a lot :)

 
On Monday, 15 April 2013 18:07:18 UTC+8, euromark wrote:
I would use string array keys:

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

but both ways should work

PS: echo $this->Form->create('Patient') is enough, as it automatically posts to itself



Am Montag, 15. April 2013 07:44:40 UTC+2 schrieb Muhammad Asyraf:
Actually i already Google several search plugin for CakePHP but most of CakePHP user recommended search plugin from CakeDC. So, i download the plugin from https://github.com/dereuromark/search and load the plugin with code: CakePlugin::load('Search'); in bootstrap.php

Then i implement the code for my file controller:

public $components = array('Search.Prg');
public $presetVars = true; // using the model configuration
public function find() {
        $this->Prg->commonProcess();
        $this->paginate['conditions'] = $this->Patient->parseCriteria($this->passedArgs);
        $this->set('patients', $this->paginate());
    }


For the model, i put this code:

public $actsAs = array('Search.Searchable');
        public $filterArgs = array(
            array('name' => 'name', 'type' => 'query', 'method' => 'filterName'),
        );

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

For the view (find.ctp), i put this code for the form: (others code are exactly same as view/index.ctp)

<div><?php
echo $this->Form->create('Patient', array(
'url' => array_merge(array('action' => 'find'), $this->params['pass'])
));
echo $this->Form->input('name', array('div' => false));
echo $this->Form->submit(__('Search'), array('div' => false));
echo $this->Form->end();
?></div>


What i try to achieve is the search plugin will do searching for "name" from table patients. However, this code seems not working but in the URL, once i do searching for example i "John" as the search term, the URL bar show as patients/find/name:john but the list of record are not showing john record only but still show all records instead of john only. 

As for the information i use CakePHP ver: 2.3.1. Is it any problem with the codes or any depreciate attributes in the coding? Sorry if this question repeated in this group but i still unable to find any solution. Most of the user claimed that it is easy to use this plugin but i'm still new in CakePHP. Hope someone can help me. 

Thanks :)

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+u...@googlegroups.com.
To post to this group, send email to cake...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: