Wednesday, February 22, 2012

Re: How to work with find syntax

great link thanks!!!

I solved it this way:
I build an array with all my conditions
$this->SearchConditions['conditions'][] = 'GObject.OBJ_INTERNET_UPLOAD
>= DATE_SUB(NOW(),INTERVAL 14 DAY)';
$this->SearchConditions['order'] = 'GObject.OBJ_INTERNET_UPLOAD ASC';
$this->SearchConditions['limit'] = '2';
and run the statement
$results = $this->GObject->find('all', array(
'conditions' => $this->SearchConditions['conditions'],
'order' => $this->SearchConditions['order'],
'limit' => $this->SearchConditions['limit'],
));

On 22 Feb., 12:56, Stephen <step...@ninjacodermonkey.co.uk> wrote:
> 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-con...
>
> Kind Regards
>  Stephen
>
> On 22 February 2012 11:20, heohni <heidi.anselstet...@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 sitehttp://ask.cakephp.organd 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
> > athttp://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: