Awesome! I hadn't seen that before.

On May 10, 2:52 pm, Sliv <[EMAIL PROTECTED]> wrote:
> https://trac.cakephp.org/milestone/2.0.0.x
>
> "Change Models to return object instances instead of arrays"
>
> On May 10, 2:34 pm, chrislewis <[EMAIL PROTECTED]> wrote:
>
> > A seemingly common misconception regarding MVC is that models just
> > hold data. This is incorrect. To use a buzzword, models represent
> > 'business models' - conceptual entities that are part of a specific
> > problem domain. So if your business/problem is a store of sorts, some
> > business models might be the  shopping cart, cart items, shopper,
> > order, etc. Business models don't just hold data - they should
> > represent the concept as a whole, and group functionality with data -
> > this is central to object oriented design. A cart then may supply
> > certain obvious data members that map directly to database fields,
> > such as the cart items, total quantity, etc. There may also be
> > functionality that make sense for the cart to supply. An example may
> > be an empty() method that purges all the items from the cart, or
> > tally() which might give a sum of the price of all contained items.
> > In my opinion, the cake's perspective of 'models' is its biggest
> > weakness. Yes, you can add methods to models that make contextual
> > sense, but it's difficult to achive any useful form of encapsulation
> > because cake's models don't really encapsulate anything! Cake models
> > represent themselves and simplistic arrays of scalar data ($this->data), 
> > and as such it requries that you know the structure, field
>
> > names and all, of any piece of data you want, whereever/whenever you
> > want it.
> > This is not at all object oriented. An object oriented 'model'
> > declares a contract - an interface - to anyone that wishes to use it.
> > This interface is simply its type, methods (method signatures), and
> > any public properties. The world should _never_ know/care how the
> > model handles its internal composition - that's the model's business.
> > Instead it should hide all this nonsense and simply state - if you
> > want my name, ask me - model->getName(). If you want my full name, ask
> > me - model->getFullName().
> > You shouldn't know/care whether or not name is a database field; if
> > whole name is a field or a dynamic concatenation of other fields (like
> > firstName and lastName). This is why we have encapsulation.
> > Controllers on the other hand should almost exclusively interpret/
> > execute commands on models based on user input from the views(s).
> > Cake's perspective of controllers seems pretty sane IMO.
>
> > I know the pain you're experiencing with the controller/model method
> > issue. Cake does not really impose good design for larger apps. I'd
> > wager the opposite in fact, and I credit most of this to it's
> > perspective on models. It can be corrected I think - and cake does
> > succeed in providing a pleasant, structured framework for web apps.
> > This is why Ive started a cakeforge project to help fix this model
> > problem in an unintrisive manner. If anyone is interested, check out
> > Object Model:http://cakeforge.org/projects/object-model/. There's a
> > small amount of very early code up at the moment, but i just started
> > and am developing in the context of a cake app Im working on. Here's a
> > controller and view snippet that show the difference when using object
> > model:
>
> >         //controller home() action
> >         function home() {
> >                 //Notice the method call; ofindAll() instead of findAll()
> >                 $this->set('posts', $this->Post->ofindAll());
> >         }
>
> >         //View code that enumerates $posts. Notice that we are not
> > interacting with post object data using cake model names
> >         //as hash keys. $posts contains Post objects - NOT cake data arrays.
> > So instead of using typical cake-style access:
> >         //$posts[$i]['Post']['title'];
> >         //we can access it as an object like so:
> >         //$posts[$i]->title;
>
> >         <div id="news-summary-content">
> >                 <?php
> >                 for($i = 0; $i < count($posts); $i++) {
> >                         e("
> >                                 <div class='summary-item'>
> >                                         <div 
> > class='title'>{$posts[$i]->title}</div>
> >                                         <div 
> > class='date'>".$sjcc->summaryDate($posts[$i]->created)."</
> > div>
> >                                         <div 
> > class='summary'>{$posts[$i]->body}</div>
> >                                 </div>
> >                         ");
> >                         if($i < count($posts) - 1) {
> >                                 e('<div class="news-horiz-line"></div>');
> >                         }
> >                 }
> >                 ?>
> >         </div>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to