Wednesday, February 22, 2012

Re: How to work with find syntax

Hello

The syntax looks fine, you should place it in your GObject model (models/g_object.php) and wrap it in a function i.e. "function myFindQuery($variable=false) { ... }"

If $variable == true etc you can include "Order / Limit" and if it's equal to false you could exclude it.

Then in your controller just use $results = $this->GObject->myFindQuery(true);

Don't forget to return your data in the model function!

See an article I wrote on something similar: http://www.ninjacodermonkey.co.uk/2012/02/keep-cakephp-dry-skinny-controllers-fat-models/

Kind Regards
 Stephen

On 22 February 2012 11:20, heohni <heidi.anselstetter@consultingteam.de> wrote:
Hi,

I have a find statement which look like this:

$results = $this->GObject->find('all', array(
               'conditions' => array(
                   'anotherfield = 1'
               ),
               'fields' => array('....'),
               'order' => 'myfield ASC',
               'limit' => 2
           ));

As I am calling this function also at a second place I want to have
the
 'order' => 'myfield ASC',
 'limit' => 2
only if I pass a variable to the function call.

But I don't know, how the syntax of the find should look then?

Please advice, thanks!!

--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php



--
Kind Regards
 Stephen

 http://www.ninjacodermonkey.co.uk


--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: