Re: Why only pass $data to view instead of model instance?

2010-11-17 Thread nurvzy
I have to agree with miles, this is a feature I've wanted for a while.
The newest 2.0 milestone has retutning the model reference as apposed
to an array as a toggle feature slated for release. Guess we'll just
have to wait and see. *fingers crossed*

Nick

On Nov 16, 12:09 pm, Jamie  wrote:
> No - the point of MVC is really to separate the manipulation of model
> data from the view through the use of a controller. There's nothing
> wrong with reading data from a model in a view, unless you like
> needless overhead. Lots of respected frameworks do it (like the Zend
> Framework).
>
> On Nov 16, 10:50 am, cricket  wrote:
>
>
>
> > The whole point of the MVC pattern is to separate the Model from the
> > View through the use of a Controller.
>
> > On Tue, Nov 16, 2010 at 3:45 AM, Joshua Muheim  wrote:
> > > Also an interesting idea, Miles. Thanks for mentioning it.
>
> > > On Fri, Nov 12, 2010 at 8:00 PM, Miles J  wrote:
> > >> I dislike this also. Cake really should have more than 1 model type:
> > >> DAOModel and DataModel.
>
> > >> One deals with database interactions, while the other manipulates a
> > >> dataset for the view.
>
> > >> However, there is nothing stopping you creating these extra models.
>
> > >> $this->set('data', new UserDataModel($this->User->find()));
>
> > >> On Nov 12, 5:23 am, Joshua Muheim  wrote:
> > >>> I'd like to warm up this topic again. :-)
>
> > >>> I decided to pass model instances to the views instead of just their
> > >>> $data attributes. So is there a way to tweak the paginator to do
> > >>> exactly this?
>
> > >>> Thanks,
> > >>> Josh
>
> > >>> On Thu, Oct 28, 2010 at 8:26 PM, euromark  
> > >>> wrote:
> > >>> > i tend to do those things "on demand"
> > >>> > using a behavior to add new keys or even doing it in the model
> > >>> > afterFind() etc often results in additional work without actually
> > >>> > needing this information
> > >>> > but of course this depends on the particular case
>
> > >>> > On 28 Okt., 20:10, cricket  wrote:
> > >>> >> On Thu, Oct 28, 2010 at 10:03 AM, euromark 
> > >>> >>  wrote:
> > >>> >> > thats not correct for PHP5 anymore
> > >>> >> > in PHP4 you needed to do this
> > >>> >> > but in PHP5 it is passed by reference by default, afaik
>
> > >>> >> Agreed on passing the model to the view. But this could also be
> > >>> >> accomplished in afterFind(), adding new key => value to the data
> > >>> >> array.
>
> > >>> > Check out the new CakePHP Questions 
> > >>> > sitehttp://cakeqs.organdhelpothers 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+unsubscr...@googlegroups.com For more options, visit this 
> > >>> > group athttp://groups.google.com/group/cake-php?hl=en
>
> > >> Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp 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+unsubscr...@googlegroups.com For more options, visit this group 
> > >> athttp://groups.google.com/group/cake-php?hl=en
>
> > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp 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+unsubscr...@googlegroups.com For more options, visit this group 
> > > athttp://groups.google.com/group/cake-php?hl=en

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


Re: Why only pass $data to view instead of model instance?

2010-11-17 Thread Zaky Katalan-Ezra
It shouldn't be like that.
Its an architect level discussions the implementation is not an issue.

It may be the right oop way to use some interface (will be in use in cake2.0
I hope) to the view but I am sure it shouldn't be the model interface




On Wed, Nov 17, 2010 at 12:46 PM, Joshua Muheim  wrote:

> Yeah, I like this discussion. Nice to have different views on the same
> issue and learn something. Thank you, guys!
>
> I guess, what RoR guys often forget, is that Ruby is a lot more a
> powerful language than PHP, so it can do magic that PHP can't and so
> for PHP frameworks one solution is better than for Ruby frameworks and
> vice versa.
>
> On Wed, Nov 17, 2010 at 8:44 AM, Zaky Katalan-Ezra 
> wrote:
> > There is a known debate about if the controller should know about the
> model
> > and view while the model and view should not know about each other
> > Or, the view should know about the model for update purpose for example.
> > I prefer the the first approach but I understand the other is ok too.
> >
> > Considering the fact that controller may have several models and several
> > views it should hide the data gathering process from the view.
> > For example:
> > You have a users model controller and view.
> > Then you decide to extract the email column to a different profile table.
> > All you need to do is playing with your models and controller and do
> nothing
> > with the view.
> >
> > But if you passed the model to the view you need now to pass the new
> profile
> > model and make changes to your view.
> >
> >
> >
> > On Wed, Nov 17, 2010 at 6:20 AM, cricket  wrote:
> >>
> >> On Tue, Nov 16, 2010 at 9:44 PM, Miles J 
> wrote:
> >> > Actually that's wrong. If this was a pure OOP framework, then we would
> >> > be passing the model or some kind of object to the view, but we are
> >> > not since Cake uses array as its primary data structure.
> >>
> >> I didn't mention OOP. But, now that you have, note that View is an
> >> object. Among its attributes is an array of data. I thought this was
> >> awkward at first, also, until I realised that it doesn't matter
> >> because View really needn't have that close a relationship with the
> >> data members themselves. That is, it wouldn't make much sense to do
> >> View::getX() or View::getY() when $x and $y are attributes of Model.
> >> Of course, I'm not going to sell anyone on that argument if they're
> >> still convinced that Model should be the object passed to the view.
> >> :-)
> >>
> >> > Say you had a method like this in your User model:
> >> >
> >> > public function isActive() {
> >> >return $this->data['User']['active'] == User::STATUS_ACTIVE;
> >> > }
> >> >
> >> > Then all you would need to do in the view is:
> >> >
> >> > if ($model->isActive())
> >> >
> >> > That cuts out the whole problem of having to manually write that
> >> > condition every time its used. It also cuts out the need of a helper
> >> > that handles this function when its unnecessary.
> >>
> >> But it's easy enough to adjust the data array in afterFind(), so that
> >> argument doesn't sway me. Think of $data as an encapsulation of your
> >> model instance. Not the entire model itself, with all of its behaviors
> >> and business logic, but the face it should present to the View. So,
> >> $data doesn't provide an isActive() method but, instead, includes the
> >> *information* that the View requires.
> >>
> >> Another example would be date formatting. Say a business needs their
> >> dates all formatted 'd-m-Y'. That's something that definitely should
> >> be handled by the model because, after all, it's the model that should
> >> deal with business logic. But it's unnecessary to call a
> >> formattedDate() method when we can just add a 'formatted_date' field
> >> to $data in afterFind(). Something like that could be put in AppModel,
> >> in fact. Either way, it's a cinch to just push it onto the array.
> >>
> >> (Another site might need to format dates according to users' locale.
> >> In that case, the logic should probably be handled in the view,
> >> perhaps with a helper.)
> >>
> >>
> >> > Furthermore, Cake models are used incorrectly in my opinion. Models
> >> > should represent a single entity of data (getters and setters for a
> >> > row in the database), while Cakes approach is a global model to
> >> > database table relation.
> >>
> >> I'd argue that Cake's ORM makes more sense. There are always going to
> >> be trade-offs when attempting to map objects to relational data, but
> >> Cake's DB table to array scheme has worked very well so far. Remember
> >> that the model's $data is not the entirety of the model. It's just the
> >> encapsulation for the View. If the latter requires more than what's
> >> been given to it, you simply have to add it in. That's business logic.
> >>
> >> 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 subscribe

Re: Why only pass $data to view instead of model instance?

2010-11-17 Thread Joshua Muheim
Yeah, I like this discussion. Nice to have different views on the same
issue and learn something. Thank you, guys!

I guess, what RoR guys often forget, is that Ruby is a lot more a
powerful language than PHP, so it can do magic that PHP can't and so
for PHP frameworks one solution is better than for Ruby frameworks and
vice versa.

On Wed, Nov 17, 2010 at 8:44 AM, Zaky Katalan-Ezra  wrote:
> There is a known debate about if the controller should know about the model
> and view while the model and view should not know about each other
> Or, the view should know about the model for update purpose for example.
> I prefer the the first approach but I understand the other is ok too.
>
> Considering the fact that controller may have several models and several
> views it should hide the data gathering process from the view.
> For example:
> You have a users model controller and view.
> Then you decide to extract the email column to a different profile table.
> All you need to do is playing with your models and controller and do nothing
> with the view.
>
> But if you passed the model to the view you need now to pass the new profile
> model and make changes to your view.
>
>
>
> On Wed, Nov 17, 2010 at 6:20 AM, cricket  wrote:
>>
>> On Tue, Nov 16, 2010 at 9:44 PM, Miles J  wrote:
>> > Actually that's wrong. If this was a pure OOP framework, then we would
>> > be passing the model or some kind of object to the view, but we are
>> > not since Cake uses array as its primary data structure.
>>
>> I didn't mention OOP. But, now that you have, note that View is an
>> object. Among its attributes is an array of data. I thought this was
>> awkward at first, also, until I realised that it doesn't matter
>> because View really needn't have that close a relationship with the
>> data members themselves. That is, it wouldn't make much sense to do
>> View::getX() or View::getY() when $x and $y are attributes of Model.
>> Of course, I'm not going to sell anyone on that argument if they're
>> still convinced that Model should be the object passed to the view.
>> :-)
>>
>> > Say you had a method like this in your User model:
>> >
>> > public function isActive() {
>> >        return $this->data['User']['active'] == User::STATUS_ACTIVE;
>> > }
>> >
>> > Then all you would need to do in the view is:
>> >
>> > if ($model->isActive())
>> >
>> > That cuts out the whole problem of having to manually write that
>> > condition every time its used. It also cuts out the need of a helper
>> > that handles this function when its unnecessary.
>>
>> But it's easy enough to adjust the data array in afterFind(), so that
>> argument doesn't sway me. Think of $data as an encapsulation of your
>> model instance. Not the entire model itself, with all of its behaviors
>> and business logic, but the face it should present to the View. So,
>> $data doesn't provide an isActive() method but, instead, includes the
>> *information* that the View requires.
>>
>> Another example would be date formatting. Say a business needs their
>> dates all formatted 'd-m-Y'. That's something that definitely should
>> be handled by the model because, after all, it's the model that should
>> deal with business logic. But it's unnecessary to call a
>> formattedDate() method when we can just add a 'formatted_date' field
>> to $data in afterFind(). Something like that could be put in AppModel,
>> in fact. Either way, it's a cinch to just push it onto the array.
>>
>> (Another site might need to format dates according to users' locale.
>> In that case, the logic should probably be handled in the view,
>> perhaps with a helper.)
>>
>>
>> > Furthermore, Cake models are used incorrectly in my opinion. Models
>> > should represent a single entity of data (getters and setters for a
>> > row in the database), while Cakes approach is a global model to
>> > database table relation.
>>
>> I'd argue that Cake's ORM makes more sense. There are always going to
>> be trade-offs when attempting to map objects to relational data, but
>> Cake's DB table to array scheme has worked very well so far. Remember
>> that the model's $data is not the entirety of the model. It's just the
>> encapsulation for the View. If the latter requires more than what's
>> been given to it, you simply have to add it in. That's business logic.
>>
>> 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+unsubscr...@googlegroups.com For more options, visit this group
>> at http://groups.google.com/group/cake-php?hl=en
>
>
>
> --
> Regards,
> Zaky Katalan-Ezra
> QA Administrator
> www.IGeneriX.com
> Sites.IGeneriX.com
> 054-7762312
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP rela

Re: Why only pass $data to view instead of model instance?

2010-11-16 Thread Zaky Katalan-Ezra
There is a known debate about if the controller should know about the model
and view while the model and view should not know about each other
Or, the view should know about the model for update purpose for example.
I prefer the the first approach but I understand the other is ok too.

Considering the fact that controller may have several models and several
views it should hide the data gathering process from the view.
For example:
You have a users model controller and view.
Then you decide to extract the email column to a different profile table.
All you need to do is playing with your models and controller and do nothing
with the view.

But if you passed the model to the view you need now to pass the new profile
model and make changes to your view.



On Wed, Nov 17, 2010 at 6:20 AM, cricket  wrote:

> On Tue, Nov 16, 2010 at 9:44 PM, Miles J  wrote:
> > Actually that's wrong. If this was a pure OOP framework, then we would
> > be passing the model or some kind of object to the view, but we are
> > not since Cake uses array as its primary data structure.
>
> I didn't mention OOP. But, now that you have, note that View is an
> object. Among its attributes is an array of data. I thought this was
> awkward at first, also, until I realised that it doesn't matter
> because View really needn't have that close a relationship with the
> data members themselves. That is, it wouldn't make much sense to do
> View::getX() or View::getY() when $x and $y are attributes of Model.
> Of course, I'm not going to sell anyone on that argument if they're
> still convinced that Model should be the object passed to the view.
> :-)
>
> > Say you had a method like this in your User model:
> >
> > public function isActive() {
> >return $this->data['User']['active'] == User::STATUS_ACTIVE;
> > }
> >
> > Then all you would need to do in the view is:
> >
> > if ($model->isActive())
> >
> > That cuts out the whole problem of having to manually write that
> > condition every time its used. It also cuts out the need of a helper
> > that handles this function when its unnecessary.
>
> But it's easy enough to adjust the data array in afterFind(), so that
> argument doesn't sway me. Think of $data as an encapsulation of your
> model instance. Not the entire model itself, with all of its behaviors
> and business logic, but the face it should present to the View. So,
> $data doesn't provide an isActive() method but, instead, includes the
> *information* that the View requires.
>
> Another example would be date formatting. Say a business needs their
> dates all formatted 'd-m-Y'. That's something that definitely should
> be handled by the model because, after all, it's the model that should
> deal with business logic. But it's unnecessary to call a
> formattedDate() method when we can just add a 'formatted_date' field
> to $data in afterFind(). Something like that could be put in AppModel,
> in fact. Either way, it's a cinch to just push it onto the array.
>
> (Another site might need to format dates according to users' locale.
> In that case, the logic should probably be handled in the view,
> perhaps with a helper.)
>
>
> > Furthermore, Cake models are used incorrectly in my opinion. Models
> > should represent a single entity of data (getters and setters for a
> > row in the database), while Cakes approach is a global model to
> > database table relation.
>
> I'd argue that Cake's ORM makes more sense. There are always going to
> be trade-offs when attempting to map objects to relational data, but
> Cake's DB table to array scheme has worked very well so far. Remember
> that the model's $data is not the entirety of the model. It's just the
> encapsulation for the View. If the latter requires more than what's
> been given to it, you simply have to add it in. That's business logic.
>
> 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+unsubscr...@googlegroups.comFor
>  more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>



-- 
Regards,
Zaky Katalan-Ezra
QA Administrator
www.IGeneriX.com
Sites.IGeneriX.com
054-7762312

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


Re: Why only pass $data to view instead of model instance?

2010-11-16 Thread Miles J
I guess it all boils down to personal preference then :P

On Nov 16, 8:20 pm, cricket  wrote:
> On Tue, Nov 16, 2010 at 9:44 PM, Miles J  wrote:
> > Actually that's wrong. If this was a pure OOP framework, then we would
> > be passing the model or some kind of object to the view, but we are
> > not since Cake uses array as its primary data structure.
>
> I didn't mention OOP. But, now that you have, note that View is an
> object. Among its attributes is an array of data. I thought this was
> awkward at first, also, until I realised that it doesn't matter
> because View really needn't have that close a relationship with the
> data members themselves. That is, it wouldn't make much sense to do
> View::getX() or View::getY() when $x and $y are attributes of Model.
> Of course, I'm not going to sell anyone on that argument if they're
> still convinced that Model should be the object passed to the view.
> :-)
>
> > Say you had a method like this in your User model:
>
> > public function isActive() {
> >        return $this->data['User']['active'] == User::STATUS_ACTIVE;
> > }
>
> > Then all you would need to do in the view is:
>
> > if ($model->isActive())
>
> > That cuts out the whole problem of having to manually write that
> > condition every time its used. It also cuts out the need of a helper
> > that handles this function when its unnecessary.
>
> But it's easy enough to adjust the data array in afterFind(), so that
> argument doesn't sway me. Think of $data as an encapsulation of your
> model instance. Not the entire model itself, with all of its behaviors
> and business logic, but the face it should present to the View. So,
> $data doesn't provide an isActive() method but, instead, includes the
> *information* that the View requires.
>
> Another example would be date formatting. Say a business needs their
> dates all formatted 'd-m-Y'. That's something that definitely should
> be handled by the model because, after all, it's the model that should
> deal with business logic. But it's unnecessary to call a
> formattedDate() method when we can just add a 'formatted_date' field
> to $data in afterFind(). Something like that could be put in AppModel,
> in fact. Either way, it's a cinch to just push it onto the array.
>
> (Another site might need to format dates according to users' locale.
> In that case, the logic should probably be handled in the view,
> perhaps with a helper.)
>
> > Furthermore, Cake models are used incorrectly in my opinion. Models
> > should represent a single entity of data (getters and setters for a
> > row in the database), while Cakes approach is a global model to
> > database table relation.
>
> I'd argue that Cake's ORM makes more sense. There are always going to
> be trade-offs when attempting to map objects to relational data, but
> Cake's DB table to array scheme has worked very well so far. Remember
> that the model's $data is not the entirety of the model. It's just the
> encapsulation for the View. If the latter requires more than what's
> been given to it, you simply have to add it in. That's business logic.

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


Re: Why only pass $data to view instead of model instance?

2010-11-16 Thread cricket
On Tue, Nov 16, 2010 at 9:44 PM, Miles J  wrote:
> Actually that's wrong. If this was a pure OOP framework, then we would
> be passing the model or some kind of object to the view, but we are
> not since Cake uses array as its primary data structure.

I didn't mention OOP. But, now that you have, note that View is an
object. Among its attributes is an array of data. I thought this was
awkward at first, also, until I realised that it doesn't matter
because View really needn't have that close a relationship with the
data members themselves. That is, it wouldn't make much sense to do
View::getX() or View::getY() when $x and $y are attributes of Model.
Of course, I'm not going to sell anyone on that argument if they're
still convinced that Model should be the object passed to the view.
:-)

> Say you had a method like this in your User model:
>
> public function isActive() {
>        return $this->data['User']['active'] == User::STATUS_ACTIVE;
> }
>
> Then all you would need to do in the view is:
>
> if ($model->isActive())
>
> That cuts out the whole problem of having to manually write that
> condition every time its used. It also cuts out the need of a helper
> that handles this function when its unnecessary.

But it's easy enough to adjust the data array in afterFind(), so that
argument doesn't sway me. Think of $data as an encapsulation of your
model instance. Not the entire model itself, with all of its behaviors
and business logic, but the face it should present to the View. So,
$data doesn't provide an isActive() method but, instead, includes the
*information* that the View requires.

Another example would be date formatting. Say a business needs their
dates all formatted 'd-m-Y'. That's something that definitely should
be handled by the model because, after all, it's the model that should
deal with business logic. But it's unnecessary to call a
formattedDate() method when we can just add a 'formatted_date' field
to $data in afterFind(). Something like that could be put in AppModel,
in fact. Either way, it's a cinch to just push it onto the array.

(Another site might need to format dates according to users' locale.
In that case, the logic should probably be handled in the view,
perhaps with a helper.)


> Furthermore, Cake models are used incorrectly in my opinion. Models
> should represent a single entity of data (getters and setters for a
> row in the database), while Cakes approach is a global model to
> database table relation.

I'd argue that Cake's ORM makes more sense. There are always going to
be trade-offs when attempting to map objects to relational data, but
Cake's DB table to array scheme has worked very well so far. Remember
that the model's $data is not the entirety of the model. It's just the
encapsulation for the View. If the latter requires more than what's
been given to it, you simply have to add it in. That's business logic.

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


Re: Why only pass $data to view instead of model instance?

2010-11-16 Thread Miles J
Actually that's wrong. If this was a pure OOP framework, then we would
be passing the model or some kind of object to the view, but we are
not since Cake uses array as its primary data structure.

Say you had a method like this in your User model:

public function isActive() {
return $this->data['User']['active'] == User::STATUS_ACTIVE;
}

Then all you would need to do in the view is:

if ($model->isActive())

That cuts out the whole problem of having to manually write that
condition every time its used. It also cuts out the need of a helper
that handles this function when its unnecessary.

Furthermore, Cake models are used incorrectly in my opinion. Models
should represent a single entity of data (getters and setters for a
row in the database), while Cakes approach is a global model to
database table relation.

On Nov 16, 3:28 pm, cricket  wrote:
> On Tue, Nov 16, 2010 at 5:22 PM, Miles J  wrote:
> > @Cricket - How so? Just because the model has database access? It
> > really doesn't matter if you pass the model to the view if you are
> > using it for convenience methods. I think you are completely missing
> > the point, this isn't about passing data to the view.
>
> Not sure I understand what you mean, either. Not providing a model (by
> default) to the view is a design decision based on "separation of
> concerns" (google it). In a well-designed MVC framework, it not only
> isn't necessary but would likely also be detrimental. And the point I
> was trying to make is that having a model available for "convenience
> methods" is no different from having it available for DB writes. ...
> Which goes against the principles of the MVC pattern. IOW, this isn't
> a "those Cake devs and their crazy notions" thing, but borne of a
> decision to utilise the MVC pattern.
>
> However, as Andy will remind us, "it's just PHP", and so it's a simple
> matter to shoot oneself in the foot if one wants.

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


Re: Why only pass $data to view instead of model instance?

2010-11-16 Thread cricket
On Tue, Nov 16, 2010 at 5:22 PM, Miles J  wrote:
> @Cricket - How so? Just because the model has database access? It
> really doesn't matter if you pass the model to the view if you are
> using it for convenience methods. I think you are completely missing
> the point, this isn't about passing data to the view.

Not sure I understand what you mean, either. Not providing a model (by
default) to the view is a design decision based on "separation of
concerns" (google it). In a well-designed MVC framework, it not only
isn't necessary but would likely also be detrimental. And the point I
was trying to make is that having a model available for "convenience
methods" is no different from having it available for DB writes. ...
Which goes against the principles of the MVC pattern. IOW, this isn't
a "those Cake devs and their crazy notions" thing, but borne of a
decision to utilise the MVC pattern.

However, as Andy will remind us, "it's just PHP", and so it's a simple
matter to shoot oneself in the foot if one wants.

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


Re: Why only pass $data to view instead of model instance?

2010-11-16 Thread Miles J
@Cricket - How so? Just because the model has database access? It
really doesn't matter if you pass the model to the view if you are
using it for convenience methods. I think you are completely missing
the point, this isn't about passing data to the view.

On Nov 16, 11:24 am, cricket  wrote:
> On Tue, Nov 16, 2010 at 2:09 PM, Jamie  wrote:
> > No - the point of MVC is really to separate the manipulation of model
> > data from the view through the use of a controller. There's nothing
> > wrong with reading data from a model in a view, unless you like
> > needless overhead. Lots of respected frameworks do it (like the Zend
> > Framework).
>
> Right, and so making the model available for reading from the view
> would NEVER lead to its manipulation. Sure.
>
> And what "needless overhead"? There are several simple (and cheap)
> ways to get your data to the view without passing the model to it.

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


Re: Why only pass $data to view instead of model instance?

2010-11-16 Thread cricket
On Tue, Nov 16, 2010 at 2:09 PM, Jamie  wrote:
> No - the point of MVC is really to separate the manipulation of model
> data from the view through the use of a controller. There's nothing
> wrong with reading data from a model in a view, unless you like
> needless overhead. Lots of respected frameworks do it (like the Zend
> Framework).

Right, and so making the model available for reading from the view
would NEVER lead to its manipulation. Sure.

And what "needless overhead"? There are several simple (and cheap)
ways to get your data to the view without passing the model to it.

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


Re: Why only pass $data to view instead of model instance?

2010-11-16 Thread Jamie
No - the point of MVC is really to separate the manipulation of model
data from the view through the use of a controller. There's nothing
wrong with reading data from a model in a view, unless you like
needless overhead. Lots of respected frameworks do it (like the Zend
Framework).

On Nov 16, 10:50 am, cricket  wrote:
> The whole point of the MVC pattern is to separate the Model from the
> View through the use of a Controller.
>
>
>
>
>
>
>
> On Tue, Nov 16, 2010 at 3:45 AM, Joshua Muheim  wrote:
> > Also an interesting idea, Miles. Thanks for mentioning it.
>
> > On Fri, Nov 12, 2010 at 8:00 PM, Miles J  wrote:
> >> I dislike this also. Cake really should have more than 1 model type:
> >> DAOModel and DataModel.
>
> >> One deals with database interactions, while the other manipulates a
> >> dataset for the view.
>
> >> However, there is nothing stopping you creating these extra models.
>
> >> $this->set('data', new UserDataModel($this->User->find()));
>
> >> On Nov 12, 5:23 am, Joshua Muheim  wrote:
> >>> I'd like to warm up this topic again. :-)
>
> >>> I decided to pass model instances to the views instead of just their
> >>> $data attributes. So is there a way to tweak the paginator to do
> >>> exactly this?
>
> >>> Thanks,
> >>> Josh
>
> >>> On Thu, Oct 28, 2010 at 8:26 PM, euromark  
> >>> wrote:
> >>> > i tend to do those things "on demand"
> >>> > using a behavior to add new keys or even doing it in the model
> >>> > afterFind() etc often results in additional work without actually
> >>> > needing this information
> >>> > but of course this depends on the particular case
>
> >>> > On 28 Okt., 20:10, cricket  wrote:
> >>> >> On Thu, Oct 28, 2010 at 10:03 AM, euromark 
> >>> >>  wrote:
> >>> >> > thats not correct for PHP5 anymore
> >>> >> > in PHP4 you needed to do this
> >>> >> > but in PHP5 it is passed by reference by default, afaik
>
> >>> >> Agreed on passing the model to the view. But this could also be
> >>> >> accomplished in afterFind(), adding new key => value to the data
> >>> >> array.
>
> >>> > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp 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+unsubscr...@googlegroups.com For more options, visit this 
> >>> > group athttp://groups.google.com/group/cake-php?hl=en
>
> >> Check out the new CakePHP Questions sitehttp://cakeqs.organd 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+unsubscr...@googlegroups.com For more options, visit this group 
> >> athttp://groups.google.com/group/cake-php?hl=en
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd 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+unsubscr...@googlegroups.com For more options, visit this group 
> > athttp://groups.google.com/group/cake-php?hl=en

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


Re: Why only pass $data to view instead of model instance?

2010-11-16 Thread cricket
The whole point of the MVC pattern is to separate the Model from the
View through the use of a Controller.

On Tue, Nov 16, 2010 at 3:45 AM, Joshua Muheim  wrote:
> Also an interesting idea, Miles. Thanks for mentioning it.
>
> On Fri, Nov 12, 2010 at 8:00 PM, Miles J  wrote:
>> I dislike this also. Cake really should have more than 1 model type:
>> DAOModel and DataModel.
>>
>> One deals with database interactions, while the other manipulates a
>> dataset for the view.
>>
>> However, there is nothing stopping you creating these extra models.
>>
>> $this->set('data', new UserDataModel($this->User->find()));
>>
>> On Nov 12, 5:23 am, Joshua Muheim  wrote:
>>> I'd like to warm up this topic again. :-)
>>>
>>> I decided to pass model instances to the views instead of just their
>>> $data attributes. So is there a way to tweak the paginator to do
>>> exactly this?
>>>
>>> Thanks,
>>> Josh
>>>
>>> On Thu, Oct 28, 2010 at 8:26 PM, euromark  
>>> wrote:
>>> > i tend to do those things "on demand"
>>> > using a behavior to add new keys or even doing it in the model
>>> > afterFind() etc often results in additional work without actually
>>> > needing this information
>>> > but of course this depends on the particular case
>>>
>>> > On 28 Okt., 20:10, cricket  wrote:
>>> >> On Thu, Oct 28, 2010 at 10:03 AM, euromark  
>>> >> wrote:
>>> >> > thats not correct for PHP5 anymore
>>> >> > in PHP4 you needed to do this
>>> >> > but in PHP5 it is passed by reference by default, afaik
>>>
>>> >> Agreed on passing the model to the view. But this could also be
>>> >> accomplished in afterFind(), adding new key => value to the data
>>> >> array.
>>>
>>> > Check out the new CakePHP Questions sitehttp://cakeqs.organd 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+unsubscr...@googlegroups.com For more options, visit this group 
>>> > athttp://groups.google.com/group/cake-php?hl=en
>>
>> 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+unsubscr...@googlegroups.com For more options, visit this group at 
>> http://groups.google.com/group/cake-php?hl=en
>>
>
> 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+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en
>

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


Re: Why only pass $data to view instead of model instance?

2010-11-16 Thread Joshua Muheim
Also an interesting idea, Miles. Thanks for mentioning it.

On Fri, Nov 12, 2010 at 8:00 PM, Miles J  wrote:
> I dislike this also. Cake really should have more than 1 model type:
> DAOModel and DataModel.
>
> One deals with database interactions, while the other manipulates a
> dataset for the view.
>
> However, there is nothing stopping you creating these extra models.
>
> $this->set('data', new UserDataModel($this->User->find()));
>
> On Nov 12, 5:23 am, Joshua Muheim  wrote:
>> I'd like to warm up this topic again. :-)
>>
>> I decided to pass model instances to the views instead of just their
>> $data attributes. So is there a way to tweak the paginator to do
>> exactly this?
>>
>> Thanks,
>> Josh
>>
>> On Thu, Oct 28, 2010 at 8:26 PM, euromark  wrote:
>> > i tend to do those things "on demand"
>> > using a behavior to add new keys or even doing it in the model
>> > afterFind() etc often results in additional work without actually
>> > needing this information
>> > but of course this depends on the particular case
>>
>> > On 28 Okt., 20:10, cricket  wrote:
>> >> On Thu, Oct 28, 2010 at 10:03 AM, euromark  
>> >> wrote:
>> >> > thats not correct for PHP5 anymore
>> >> > in PHP4 you needed to do this
>> >> > but in PHP5 it is passed by reference by default, afaik
>>
>> >> Agreed on passing the model to the view. But this could also be
>> >> accomplished in afterFind(), adding new key => value to the data
>> >> array.
>>
>> > Check out the new CakePHP Questions sitehttp://cakeqs.organd 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+unsubscr...@googlegroups.com For more options, visit this group 
>> > athttp://groups.google.com/group/cake-php?hl=en
>
> 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+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en
>

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


Re: Why only pass $data to view instead of model instance?

2010-11-12 Thread Miles J
I dislike this also. Cake really should have more than 1 model type:
DAOModel and DataModel.

One deals with database interactions, while the other manipulates a
dataset for the view.

However, there is nothing stopping you creating these extra models.

$this->set('data', new UserDataModel($this->User->find()));

On Nov 12, 5:23 am, Joshua Muheim  wrote:
> I'd like to warm up this topic again. :-)
>
> I decided to pass model instances to the views instead of just their
> $data attributes. So is there a way to tweak the paginator to do
> exactly this?
>
> Thanks,
> Josh
>
> On Thu, Oct 28, 2010 at 8:26 PM, euromark  wrote:
> > i tend to do those things "on demand"
> > using a behavior to add new keys or even doing it in the model
> > afterFind() etc often results in additional work without actually
> > needing this information
> > but of course this depends on the particular case
>
> > On 28 Okt., 20:10, cricket  wrote:
> >> On Thu, Oct 28, 2010 at 10:03 AM, euromark  
> >> wrote:
> >> > thats not correct for PHP5 anymore
> >> > in PHP4 you needed to do this
> >> > but in PHP5 it is passed by reference by default, afaik
>
> >> Agreed on passing the model to the view. But this could also be
> >> accomplished in afterFind(), adding new key => value to the data
> >> array.
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd 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+unsubscr...@googlegroups.com For more options, visit this group 
> > athttp://groups.google.com/group/cake-php?hl=en

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


Re: Why only pass $data to view instead of model instance?

2010-11-12 Thread Joshua Muheim
I'd like to warm up this topic again. :-)

I decided to pass model instances to the views instead of just their
$data attributes. So is there a way to tweak the paginator to do
exactly this?

Thanks,
Josh

On Thu, Oct 28, 2010 at 8:26 PM, euromark  wrote:
> i tend to do those things "on demand"
> using a behavior to add new keys or even doing it in the model
> afterFind() etc often results in additional work without actually
> needing this information
> but of course this depends on the particular case
>
>
> On 28 Okt., 20:10, cricket  wrote:
>> On Thu, Oct 28, 2010 at 10:03 AM, euromark  
>> wrote:
>> > thats not correct for PHP5 anymore
>> > in PHP4 you needed to do this
>> > but in PHP5 it is passed by reference by default, afaik
>>
>> Agreed on passing the model to the view. But this could also be
>> accomplished in afterFind(), adding new key => value to the data
>> array.
>
> 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+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en
>

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


Re: Why only pass $data to view instead of model instance?

2010-10-28 Thread euromark
i tend to do those things "on demand"
using a behavior to add new keys or even doing it in the model
afterFind() etc often results in additional work without actually
needing this information
but of course this depends on the particular case


On 28 Okt., 20:10, cricket  wrote:
> On Thu, Oct 28, 2010 at 10:03 AM, euromark  wrote:
> > thats not correct for PHP5 anymore
> > in PHP4 you needed to do this
> > but in PHP5 it is passed by reference by default, afaik
>
> Agreed on passing the model to the view. But this could also be
> accomplished in afterFind(), adding new key => value to the data
> array.

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


Re: Why only pass $data to view instead of model instance?

2010-10-28 Thread cricket
On Thu, Oct 28, 2010 at 10:03 AM, euromark  wrote:
> thats not correct for PHP5 anymore
> in PHP4 you needed to do this
> but in PHP5 it is passed by reference by default, afaik

Agreed on passing the model to the view. But this could also be
accomplished in afterFind(), adding new key => value to the data
array.

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


Re: Why only pass $data to view instead of model instance?

2010-10-28 Thread euromark
thats not correct for PHP5 anymore
in PHP4 you needed to do this
but in PHP5 it is passed by reference by default, afaik


On 28 Okt., 15:06, Hashim Ikram  wrote:
> I have not try it but if you want to set instance of a Model, I think you
> should pass it as
>
> $this->set('book', &$this->book)
>
> In other words you should pass it by reference.
>
> Regards
> Hashim Ikram
>
> On Thu, Oct 28, 2010 at 3:45 PM, Joshua Muheim  wrote:
> > Thanks for your reply.
>
> > You mean I should stick the code above into my view (including the
> > App::import(...))? I agree with you, this would quite break the MVC
> > convention. But what speaks against using this code in the
> > controller...
>
> > $this->set('book', $this->Book);
>
> > and then just using the $book instance in the view like so?
>
> >  >  echo "Rent: ".$book->isRent();
> > ?>
>
> > IMHO, this wouldn't break MVC, but still CakePHP doesn't suggest it,
> > as far as I can see. Why?
>
> > On Thu, Oct 28, 2010 at 12:36 PM, Hashim Ikram  wrote:
> > > Hi Josh,
> > >          It is better to use Model functions in controller according to
> > MVC
> > > convention, but if you want to use model function in view you can use it
> > in
> > > this way.
> > > /* - */
> > > App::import('Model',array('Book'));
> > > $bookObj = new Book();
>
> > > $isRent = $bookObj->isRent();
>
> > /*---*/
>
> > > hope it helps you but still I would say that as you are useing a MVC
> > > framework so you should get Data in controller and then pass it to view.
> > But
> > > really sometimes we have mold or break the convention rules so choice is
> > > yours :)
>
> > > Regards
> > > Hashim Ikram
>
> > > On Thu, Oct 28, 2010 at 3:10 PM, euromark 
> > > wrote:
>
> > >> i agree that this would be handy at some point
> > >> but it helps to keep the layers separated
> > >> otherwise one would be tempted to read/write to the DB in the views
>
> > >> i usually use static model methods for this
>
> > >> /** static **/
> > >> function isRent($data) {
> > >>  return !empty($data[$this->alias]['rent_user_id']);
> > >> }
>
> > >> you can now call it anywhere (model, controller, behavior, view)
> > >> be sure you pass the data, though
>
> > >> PS: actually it has another upside. you can use it inside iterations
> > >> as well - like in foreach() loops in the view
>
> > >> On 28 Okt., 11:13, psybear83  wrote:
> > >> > Hi everybody
>
> > >> > Something I don't really like in CakePHP is that one seems to be
> > >> > always only working with the $data array instead of "real" model
> > >> > instances. I hate to name Ruby on Rails again, but in RoR, I normally
> > >> > pass a model instace to a view, and there I can do handy stuff like
> > >> > calling methods on that model etc.
>
> > >> > But in CakePHP it seems normal to only pass the $data of the model. So
> > >> > I can't call any methods on it.
>
> > >> > For example, I have a Medium (e.g. a book) model that can be rent. It
> > >> > has a method isRent():
>
> > >> > function isRent() {
> > >> >   return !empty($this->data['Medium']['rent_user_id']);
>
> > >> > }
>
> > >> > So when the rent_user_id is empty, the medium is rent to that user.
>
> > >> > It would be really handy to use this method also in a view, but it
> > >> > seems I can't. Is the only solution to set another parameter for the
> > >> > view, like so?
>
> > >> > $this->set('isRent', $model->isRent());
>
> > >> > Thanks for help
> > >> > Josh
>
> > >> Check out the new CakePHP Questions sitehttp://cakeqs.organd 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+unsubscr...@googlegroups.comFor
> > >>  more options, visit this group
> > >> athttp://groups.google.com/group/cake-php?hl=en
>
> > > Check out the new CakePHP Questions sitehttp://cakeqs.organd 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+unsubscr...@googlegroups.comFor
> > >  more options, visit this group at
> > >http://groups.google.com/group/cake-php?hl=en
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd 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+unsubscr...@googlegroups.comFor
> >  more options, visit this group at
> >http://groups.google.co

Re: Why only pass $data to view instead of model instance?

2010-10-28 Thread Hashim Ikram
I have not try it but if you want to set instance of a Model, I think you
should pass it as

$this->set('book', &$this->book)

In other words you should pass it by reference.

Regards
Hashim Ikram


On Thu, Oct 28, 2010 at 3:45 PM, Joshua Muheim  wrote:

> Thanks for your reply.
>
> You mean I should stick the code above into my view (including the
> App::import(...))? I agree with you, this would quite break the MVC
> convention. But what speaks against using this code in the
> controller...
>
> $this->set('book', $this->Book);
>
> and then just using the $book instance in the view like so?
>
>   echo "Rent: ".$book->isRent();
> ?>
>
> IMHO, this wouldn't break MVC, but still CakePHP doesn't suggest it,
> as far as I can see. Why?
>
> On Thu, Oct 28, 2010 at 12:36 PM, Hashim Ikram  wrote:
> > Hi Josh,
> >  It is better to use Model functions in controller according to
> MVC
> > convention, but if you want to use model function in view you can use it
> in
> > this way.
> > /* - */
> > App::import('Model',array('Book'));
> > $bookObj = new Book();
> >
> > $isRent = $bookObj->isRent();
> >
> /*---*/
> >
> > hope it helps you but still I would say that as you are useing a MVC
> > framework so you should get Data in controller and then pass it to view.
> But
> > really sometimes we have mold or break the convention rules so choice is
> > yours :)
> >
> > Regards
> > Hashim Ikram
> >
> >
> > On Thu, Oct 28, 2010 at 3:10 PM, euromark 
> > wrote:
> >>
> >> i agree that this would be handy at some point
> >> but it helps to keep the layers separated
> >> otherwise one would be tempted to read/write to the DB in the views
> >>
> >> i usually use static model methods for this
> >>
> >> /** static **/
> >> function isRent($data) {
> >>  return !empty($data[$this->alias]['rent_user_id']);
> >> }
> >>
> >> you can now call it anywhere (model, controller, behavior, view)
> >> be sure you pass the data, though
> >>
> >> PS: actually it has another upside. you can use it inside iterations
> >> as well - like in foreach() loops in the view
> >>
> >>
> >> On 28 Okt., 11:13, psybear83  wrote:
> >> > Hi everybody
> >> >
> >> > Something I don't really like in CakePHP is that one seems to be
> >> > always only working with the $data array instead of "real" model
> >> > instances. I hate to name Ruby on Rails again, but in RoR, I normally
> >> > pass a model instace to a view, and there I can do handy stuff like
> >> > calling methods on that model etc.
> >> >
> >> > But in CakePHP it seems normal to only pass the $data of the model. So
> >> > I can't call any methods on it.
> >> >
> >> > For example, I have a Medium (e.g. a book) model that can be rent. It
> >> > has a method isRent():
> >> >
> >> > function isRent() {
> >> >   return !empty($this->data['Medium']['rent_user_id']);
> >> >
> >> > }
> >> >
> >> > So when the rent_user_id is empty, the medium is rent to that user.
> >> >
> >> > It would be really handy to use this method also in a view, but it
> >> > seems I can't. Is the only solution to set another parameter for the
> >> > view, like so?
> >> >
> >> > $this->set('isRent', $model->isRent());
> >> >
> >> > Thanks for help
> >> > Josh
> >>
> >> 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+unsubscr...@googlegroups.comFor
> >>  more options, visit this group
> >> at http://groups.google.com/group/cake-php?hl=en
> >
> > 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+unsubscr...@googlegroups.comFor
> >  more options, visit this group at
> > http://groups.google.com/group/cake-php?hl=en
> >
>
> 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+unsubscr...@googlegroups.comFor
>  more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>

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

Re: Why only pass $data to view instead of model instance?

2010-10-28 Thread euromark
i need to correct myself

/** static **/
function isRent($data) {
 return !empty($data['rent_user_id']);
}

and you simply use it this way:

//in views
if (Model::isRent($book['Book'])) {...}

this way it it can be used in any iteration as well


On 28 Okt., 12:45, Joshua Muheim  wrote:
> Thanks for your reply.
>
> You mean I should stick the code above into my view (including the
> App::import(...))? I agree with you, this would quite break the MVC
> convention. But what speaks against using this code in the
> controller...
>
> $this->set('book', $this->Book);
>
> and then just using the $book instance in the view like so?
>
>    echo "Rent: ".$book->isRent();
> ?>
>
> IMHO, this wouldn't break MVC, but still CakePHP doesn't suggest it,
> as far as I can see. Why?
>
>
>
>
>
>
>
> On Thu, Oct 28, 2010 at 12:36 PM, Hashim Ikram  wrote:
> > Hi Josh,
> >  It is better to use Model functions in controller according to MVC
> > convention, but if you want to use model function in view you can use it in
> > this way.
> > /* - */
> > App::import('Model',array('Book'));
> > $bookObj = new Book();
>
> > $isRent = $bookObj->isRent();
> > /*---*/
>
> > hope it helps you but still I would say that as you are useing a MVC
> > framework so you should get Data in controller and then pass it to view. But
> > really sometimes we have mold or break the convention rules so choice is
> > yours :)
>
> > Regards
> > Hashim Ikram
>
> > On Thu, Oct 28, 2010 at 3:10 PM, euromark 
> > wrote:
>
> >> i agree that this would be handy at some point
> >> but it helps to keep the layers separated
> >> otherwise one would be tempted to read/write to the DB in the views
>
> >> i usually use static model methods for this
>
> >> /** static **/
> >> function isRent($data) {
> >>  return !empty($data[$this->alias]['rent_user_id']);
> >> }
>
> >> you can now call it anywhere (model, controller, behavior, view)
> >> be sure you pass the data, though
>
> >> PS: actually it has another upside. you can use it inside iterations
> >> as well - like in foreach() loops in the view
>
> >> On 28 Okt., 11:13, psybear83  wrote:
> >> > Hi everybody
>
> >> > Something I don't really like in CakePHP is that one seems to be
> >> > always only working with the $data array instead of "real" model
> >> > instances. I hate to name Ruby on Rails again, but in RoR, I normally
> >> > pass a model instace to a view, and there I can do handy stuff like
> >> > calling methods on that model etc.
>
> >> > But in CakePHP it seems normal to only pass the $data of the model. So
> >> > I can't call any methods on it.
>
> >> > For example, I have a Medium (e.g. a book) model that can be rent. It
> >> > has a method isRent():
>
> >> > function isRent() {
> >> >   return !empty($this->data['Medium']['rent_user_id']);
>
> >> > }
>
> >> > So when the rent_user_id is empty, the medium is rent to that user.
>
> >> > It would be really handy to use this method also in a view, but it
> >> > seems I can't. Is the only solution to set another parameter for the
> >> > view, like so?
>
> >> > $this->set('isRent', $model->isRent());
>
> >> > Thanks for help
> >> > Josh
>
> >> Check out the new CakePHP Questions sitehttp://cakeqs.organd 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+unsubscr...@googlegroups.com For more options, visit this group
> >> athttp://groups.google.com/group/cake-php?hl=en
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd 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+unsubscr...@googlegroups.com For more options, visit this group at
> >http://groups.google.com/group/cake-php?hl=en

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


Re: Why only pass $data to view instead of model instance?

2010-10-28 Thread Joshua Muheim
Thanks for your reply.

You mean I should stick the code above into my view (including the
App::import(...))? I agree with you, this would quite break the MVC
convention. But what speaks against using this code in the
controller...

$this->set('book', $this->Book);

and then just using the $book instance in the view like so?

isRent();
?>

IMHO, this wouldn't break MVC, but still CakePHP doesn't suggest it,
as far as I can see. Why?

On Thu, Oct 28, 2010 at 12:36 PM, Hashim Ikram  wrote:
> Hi Josh,
>  It is better to use Model functions in controller according to MVC
> convention, but if you want to use model function in view you can use it in
> this way.
> /* - */
> App::import('Model',array('Book'));
> $bookObj = new Book();
>
> $isRent = $bookObj->isRent();
> /*---*/
>
> hope it helps you but still I would say that as you are useing a MVC
> framework so you should get Data in controller and then pass it to view. But
> really sometimes we have mold or break the convention rules so choice is
> yours :)
>
> Regards
> Hashim Ikram
>
>
> On Thu, Oct 28, 2010 at 3:10 PM, euromark 
> wrote:
>>
>> i agree that this would be handy at some point
>> but it helps to keep the layers separated
>> otherwise one would be tempted to read/write to the DB in the views
>>
>> i usually use static model methods for this
>>
>> /** static **/
>> function isRent($data) {
>>  return !empty($data[$this->alias]['rent_user_id']);
>> }
>>
>> you can now call it anywhere (model, controller, behavior, view)
>> be sure you pass the data, though
>>
>> PS: actually it has another upside. you can use it inside iterations
>> as well - like in foreach() loops in the view
>>
>>
>> On 28 Okt., 11:13, psybear83  wrote:
>> > Hi everybody
>> >
>> > Something I don't really like in CakePHP is that one seems to be
>> > always only working with the $data array instead of "real" model
>> > instances. I hate to name Ruby on Rails again, but in RoR, I normally
>> > pass a model instace to a view, and there I can do handy stuff like
>> > calling methods on that model etc.
>> >
>> > But in CakePHP it seems normal to only pass the $data of the model. So
>> > I can't call any methods on it.
>> >
>> > For example, I have a Medium (e.g. a book) model that can be rent. It
>> > has a method isRent():
>> >
>> > function isRent() {
>> >   return !empty($this->data['Medium']['rent_user_id']);
>> >
>> > }
>> >
>> > So when the rent_user_id is empty, the medium is rent to that user.
>> >
>> > It would be really handy to use this method also in a view, but it
>> > seems I can't. Is the only solution to set another parameter for the
>> > view, like so?
>> >
>> > $this->set('isRent', $model->isRent());
>> >
>> > Thanks for help
>> > Josh
>>
>> 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+unsubscr...@googlegroups.com For more options, visit this group
>> at http://groups.google.com/group/cake-php?hl=en
>
> 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+unsubscr...@googlegroups.com For more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>

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


Re: Why only pass $data to view instead of model instance?

2010-10-28 Thread Hashim Ikram
Hi Josh,
 It is better to use Model functions in controller according to MVC
convention, but if you want to use model function in view you can use it in
this way.
/* - */
App::import('Model',array('Book'));
$bookObj = new Book();

$isRent = $bookObj->isRent();
/*---*/

hope it helps you but still I would say that as you are useing a MVC
framework so you should get Data in controller and then pass it to view. But
really sometimes we have mold or break the convention rules so choice is
yours :)

Regards
Hashim Ikram


On Thu, Oct 28, 2010 at 3:10 PM, euromark wrote:

> i agree that this would be handy at some point
> but it helps to keep the layers separated
> otherwise one would be tempted to read/write to the DB in the views
>
> i usually use static model methods for this
>
> /** static **/
> function isRent($data) {
>  return !empty($data[$this->alias]['rent_user_id']);
> }
>
> you can now call it anywhere (model, controller, behavior, view)
> be sure you pass the data, though
>
> PS: actually it has another upside. you can use it inside iterations
> as well - like in foreach() loops in the view
>
>
> On 28 Okt., 11:13, psybear83  wrote:
> > Hi everybody
> >
> > Something I don't really like in CakePHP is that one seems to be
> > always only working with the $data array instead of "real" model
> > instances. I hate to name Ruby on Rails again, but in RoR, I normally
> > pass a model instace to a view, and there I can do handy stuff like
> > calling methods on that model etc.
> >
> > But in CakePHP it seems normal to only pass the $data of the model. So
> > I can't call any methods on it.
> >
> > For example, I have a Medium (e.g. a book) model that can be rent. It
> > has a method isRent():
> >
> > function isRent() {
> >   return !empty($this->data['Medium']['rent_user_id']);
> >
> > }
> >
> > So when the rent_user_id is empty, the medium is rent to that user.
> >
> > It would be really handy to use this method also in a view, but it
> > seems I can't. Is the only solution to set another parameter for the
> > view, like so?
> >
> > $this->set('isRent', $model->isRent());
> >
> > Thanks for help
> > Josh
>
> 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+unsubscr...@googlegroups.comFor
>  more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>

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


Re: Why only pass $data to view instead of model instance?

2010-10-28 Thread euromark
i agree that this would be handy at some point
but it helps to keep the layers separated
otherwise one would be tempted to read/write to the DB in the views

i usually use static model methods for this

/** static **/
function isRent($data) {
 return !empty($data[$this->alias]['rent_user_id']);
}

you can now call it anywhere (model, controller, behavior, view)
be sure you pass the data, though

PS: actually it has another upside. you can use it inside iterations
as well - like in foreach() loops in the view


On 28 Okt., 11:13, psybear83  wrote:
> Hi everybody
>
> Something I don't really like in CakePHP is that one seems to be
> always only working with the $data array instead of "real" model
> instances. I hate to name Ruby on Rails again, but in RoR, I normally
> pass a model instace to a view, and there I can do handy stuff like
> calling methods on that model etc.
>
> But in CakePHP it seems normal to only pass the $data of the model. So
> I can't call any methods on it.
>
> For example, I have a Medium (e.g. a book) model that can be rent. It
> has a method isRent():
>
> function isRent() {
>   return !empty($this->data['Medium']['rent_user_id']);
>
> }
>
> So when the rent_user_id is empty, the medium is rent to that user.
>
> It would be really handy to use this method also in a view, but it
> seems I can't. Is the only solution to set another parameter for the
> view, like so?
>
> $this->set('isRent', $model->isRent());
>
> Thanks for help
> Josh

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


Why only pass $data to view instead of model instance?

2010-10-28 Thread psybear83
Hi everybody

Something I don't really like in CakePHP is that one seems to be
always only working with the $data array instead of "real" model
instances. I hate to name Ruby on Rails again, but in RoR, I normally
pass a model instace to a view, and there I can do handy stuff like
calling methods on that model etc.

But in CakePHP it seems normal to only pass the $data of the model. So
I can't call any methods on it.

For example, I have a Medium (e.g. a book) model that can be rent. It
has a method isRent():

function isRent() {
  return !empty($this->data['Medium']['rent_user_id']);
}

So when the rent_user_id is empty, the medium is rent to that user.

It would be really handy to use this method also in a view, but it
seems I can't. Is the only solution to set another parameter for the
view, like so?

$this->set('isRent', $model->isRent());

Thanks for help
Josh

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