Hi and thanks for the reply.
Yea, I had seen this plugin, it's a fork of the CakeDC plugin. And I see in
the docs that you can do something like this:
class Article extends AppModel {
public $filterArgs = array(
'enhanced_search' => array('type' => 'like', 'field' =>
array('Article.name', 'OtherModel.name'))
}
}
But what is not explained is, how do I get the plugin to actually search
within the 'OtherModel' Model? I ask because later in the Controller you
have:
class ArticlesController extends AppController {
public $components = array('Search.Prg');
public $presetVars = true; // using the model configuration
public function find() {
$this->Prg->commonProcess();
$this->paginate['conditions'] = $this->*Article*
->parseCriteria($this->passedArgs);
$this->set('articles', $this->paginate());
}
}
And in the .ctp you have:
echo $this->Form->create('*Article*', array(
'url' => array_merge(array('action' => 'find'), $this->params['pass'])
));
As you can see, the Article Model is always referenced. So if I want to
search for a field from another model, like the 'OtherModel.name' example
above, it crashes, saying:
Column not found: 1054 Unknown column ' OtherModel.name ' in 'where clause'
The SQL is more or less:
SELECT `Article`.`id`, ... FROM `articles` WHERE ((`Article`.`name` LIKE
'%foo%') OR (`OtherModel`.`name` LIKE '%foo%'))
Obviously OtherModel.name is not going to be found in Article.
What I need to do is have a general Search box that searches in 4-5
different Models. There is no relation between those Models. So I am not
sure which Model to put the filterArgs array, which Controller to put the
presetVars array and find() function, and how to call it all in my .ctp so
that it can return results from all 5 of these Models, not just one.
Can this plugin do it?
Many thanks!
On Friday, June 15, 2012 10:08:11 AM UTC+2, euromark wrote:
>
> try this one:
> https://github.com/dereuromark/search
>
> it can handle multiple fields across models for a like term etc
>
> 'field' => array('Primary.field', 'Secondary.other_field')
>
>
> Am Freitag, 15. Juni 2012 00:06:03 UTC+2 schrieb Bob Bowen:
>>
>> Is there any way to make this work? As I understand it you have to
>> enable Search.Searchable in the $actsAs, and define $filterArgs for each
>> Model, then add Search.Prg to $components and define $presetVars in the
>> Controller.
>>
>> Then in your .ctp file you put something like this:
>>
>> echo $this->Form->create('MyModel', array('url' =>
>> array_merge(array('action' => 'find'), $this->params['pass'])));
>> echo $this->Form->input('search', array('div' => false));
>> echo $this->Form->submit(__('Search', true), array('div' => false));
>> echo $this->Form->end();
>>
>> But this allows you to search in one Model at a time. Is there any way to
>> define a search form with one search field and have it look in various
>> fields within various Models?
>>
>> Thanks
>> Bob
>>
>
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php