Thursday, March 25, 2010

Re: Find Output Thoughts (why the not remove ['ModelName'])

I see, the thing about save (and also reminded me of the form data) is
a good point.

I guess this might be indeed the better format for the default find
data.
Guess I'll just do my own "find" method for beautifying data for my
views.

Thanks to all for the reply.

Bake on

On 25 mar, 09:12, euromark <dereurom...@googlemail.com> wrote:
> why the overhead?
>
> controller:
> $article = $this->Article->read(null, $id);
> $this->set(compact("article"));
>
> view:
> echo $article['Article']['field']; etc
>
> usually you have left joins in it anyway - so parent models are
> retrieved too and could/need to be accessed as well:
>
> echo $article['User']['field'];
> echo $article['Category']['field'];
>
> and therefore it is nice to have such a non-flat array...
>
> On 25 Mrz., 10:45, "Richard@Home" <richardath...@gmail.com> wrote:
>
> > I'm with WebbedIT on this one.
>
> > And besides, you can always do something like the following in your
> > controller:
>
> > $data = $this->Article->read(null, $id);
> > $article = $data['Article'];
> > $this->set(compact("article", "data"));
>
> > and access $article['name'] etc. in your view.
>
> > On Mar 24, 7:52 pm, Lucas Costa <lucasrco...@gmail.com> wrote:
>
> > > Hi. I've been working with Cake for a while and something always comes
> > > up to my mind when writing a view, which I'll share:
>
> > > We all know how Cake spits a simple find('first'), right:
>
> > > Array
> > > (
> > >     [ModelName] => Array
> > >         (
> > >             [id] => 83
> > >             [field1] => value1
> > >         )
> > >     [AssociatedModelName] => Array
> > >         (
> > >             [id] => 1
> > >             [field1] => value1
> > >         )
> > > )
>
> > > Now, I find it tiresome to have to type the ['ModelName'] everytime I
> > > want to play with the data. And also sometimes it seems a little
> > > redundant. For example: What do you usually do when finding an
> > > article:
>
> > > $article = $this->Articles->findById(1); (using $data all the time
> > > seems little intuitive for me since sometimes we have a lot of
> > > different data shipping to the view)
>
> > > To get the name of the article we would use $article['Article']
> > > ['name']. See... article->Article->name.
>
> > > And I keep thinking that since, by convention, all model names are
> > > CamelCased, and fieldnames are lowercased, and arrays are case
> > > sensitive, usually, we wouldn't have a collision and then we would
> > > have more beatiful data:
>
> > > $article['name'];
> > > $article['Author']['name'];
> > > and so forth....
>
> > > so, what am I missing here? :-)

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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

To unsubscribe from this group, send email to cake-php+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

No comments: