About Controller::postConditions(): it is a handy method that will let you
convert an array of POST data to its suitable findAll conditions array. So
for example if you have:

$postData = array (
        'Model1' => array (
                'field11' => 'value11',
                'field12' => 'value12'
        ),
        'Model2' => array (
                'field21' => 'value21'
        )
)

Doing:

$this->postConditions($postData);

Will return an array of the form:

Array (
        'Model1.field11' => 'value11',
        'Model1.field12' => 'value12',
        'Model2.field21' => 'value21'
);

This can also be obtained on CakePHP 1.2 with the amazing Set::extract()
method (Nate and Larry, thanks for that beautiful peace of work)

So the previous example I gave you could be changed to:

function search()
{
        if (!empty($this->data))
        {
                $conditions = $this->postConditions($this->data);

                $conditions['Candidato.nome'] = 'LIKE %'
$conditions['Candidato.nome'] . '%';

                $results = $this->Candadato->findAll($conditions);

                $this->set('candidatos', $results);

                $this->render('index');
        }
}

-MI

---------------------------------------------------------------------------

Remember, smart coders answer ten questions for every question they ask. 
So be smart, be cool, and share your knowledge. 

BAKE ON!

blog: http://www.MarianoIglesias.com.ar


-----Mensaje original-----
De: [email protected] [mailto:[EMAIL PROTECTED] En nombre
de Norman
Enviado el: Lunes, 26 de Febrero de 2007 09:49 p.m.
Para: Cake PHP
Asunto: Re: Ambiguous columns in findAll()

The $conditions = array('Candidato.nome' => "LIKE %{$search_term}%");
worked as a champ. And this even helped me to better understand the
innards of the FindAll method.

Nate, I was not able to fully understand how to use postConditions().
Im still on my first month of using cakephp, so if you know some place
where I can see some working/example code using this method, I would
love to learn from it.


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to