On Thu, Mar 24, 2011 at 6:24 AM, varai <[email protected]> wrote:
> Hi,
>
> I'm new to cakePHP and OOP.
>
> The code below is from
> http://book.cakephp.org/view/875/x1-3-Collection#!/view/977/Controller-Methods.
> Can someone please explain the postConditons below? I don't understand
> how can num_items key contain '>=' and referrer key contain 'LIKE'.
> What does the word compact in find('all', compact('condtions')) mean?
> Thank you.
>
> /*
> Contents of $this->data
> array(
> 'Order' => array(
> 'num_items' => '4',
> 'referrer' => 'Ye Olde'
> )
> )
> */
>
> //Let’s get orders that have at least 4 items and contain ‘Ye Olde’
> $condtions=$this->postConditions(
> $this->data,
> array(
> 'num_items' => '>=',
> 'referrer' => 'LIKE'
> )
> );
> $orders = $this->Order->find("all",compact('condtions'));
I think the best thing you could do, as a new Cake user, is to pretend
you never saw this method. It's is a little-known shortcut that
requires a pretty good understanding of how Cake operates.
That said, what the method does is apply the values from the 2nd param
array to the find conditions so as to change the query. The above
example would be equivalent to:
$this->Order->find(
'all',
array(
'conditions' => array(
'num_items >=' => '4',
'referrer LIKE' => 'Ye Olde'
)
)
)
And compact() is another convenience:
http://php.net/manual/en/function.compact.php
--
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