Yeah that looks like a nifty approach,

Will give that a shot! Thanks


I am just cleaning up my app I have been playing round with over the last
few months so as I learn to make things better and evolve I see functions I
have made where some grab 3 fields, some grab all, other 10 or so.

So there is a mess of functions grabbing specific data, all data, little
data so was just wondering how other people do it. But you idea would allow
me to use the same function and grab what I need / don’t need.

I think I may expand on your idea and create it where you can choose to
'keep' or 'remove' fields rather than having to type 20 names to keep only
type out the few you don’t need or what not and use something like
array_diff_key or array_intersect_key to keep or remove based on
$this->myFields = array('field_one, 'field_two', 'and_some_other');

Dave




-----Original Message-----
From: teknoid [mailto:teknoid.cake...@gmail.com] 
Sent: September-26-09 6:29 PM
To: CakePHP
Subject: Re: Just curious question


... haven't tested, but something like this should work:

In the model:
$this->myFields = array('field_one, 'field_two', 'and_some_other');

public function modifyRequiredFields($additionalFields) {
array_push($this->myFields, $additionalFields);

 return $this->myFields;
}

In the controller:
$this->ModelName->find('all', array('fields' => $this->ModelName-
>modifyRequiredFields(array('i_also_need_this', 'and_this'));

... or ...

if it's a "standard" find()

$this->ModelName->find('all', array('fields' => $this->ModelName-
>myFields));

On Sep 26, 3:14 pm, "Dave Maharaj :: WidePixels.com"
<d...@widepixels.com> wrote:
> Just wondering if anyone has an opinion or fact about this.
>
> When pulling model data, keep it simple so Users controller getting 
> straight info from Users database.
> Users table has 15 fields.
>
> You may only need 5 fields data and in another case you may need all 
> 15 fields.
>
> Is it best to specify the fields you need always?
> I guess the size of the data in the fields will make a difference.
> I am just thinking in regards to my app where i need a few fields, 
> then i need all fields does it take more time to process a detailed 
> request when you specify each individual field when you need info from 
> 10 fields as opposed to *just and get them all.
>
> What is best practise? Or in this case its more of a try both and see 
> what works best for each app?
>
> Thanks
>
> Dave


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to