morning mate,
I would have said your function would have to be something more like :
function search($conditions=NULL) {
if (empty($this->data)) {
$this->render();
} else {
$conditions =array();
$search_term = $this->data['Test']['identifiant_facture'];
$conditions[] = "Test.identifiant_facture LIKE % {$search_term}%";
$search = $this->Test->findAll($conditions);
$this->set('data', $search);
$this->render();
}
}
Things to note :
- In your form your search field must have the name :
data[Test][identifiant_facture]
i.e. <input name="data[Test][identifiant_facture]" ...
- finderQuery expects a SQL statement as opposed to a set of conditions
- conditions should not be a multi dimensional array
- you didn't seem to be using the $array variable
- when "setting" variables to the view you do not need to include the $ sign
i.e. $this->set('data', $search);
I think that is about all. You might want to refer to the manual and
the API for some of this information.
HTH,
mikee
On 01/02/07, Mani <[EMAIL PROTECTED]> wrote:
>
> Hi World,
> I met a problem and I can not resolve it. I created an intranet and I
> want to integrate a "search" form (from databases). I put this code in
> the controller, but I have a message on my computer, "Warning: Invalid
> argument supplied for foreach()...".
> Would you help me?
>
> function search($conditions=NULL) {
> $array=array();
> if(empty($this->data)) {
> $this->render();
> } else {
> $conditions =array();
> $search_term = $this->data['Test']['identifiant_facture'];
> $conditions['Test']['identifiant_facture'] = "LIKE %
> {$search_term}%";
> $search = $this->Test->finderQuery($conditions);
> $this->set('$form', $search);
> //$this->render("search");
> print_r($search);
> }
> }
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---