Ever heard of a can of worms :)
(The whole "-This is MVC. -No, this is MVC" thing can turn nasty at
times.)

Cake allows no direct access to Models from Views. That is how the MVC
pattern has been implemented in Cake even though there are other
interpretations in other Frameworks. If everyone had the same
preference there wouldn't be such an abundance of frameworks doing
more or less the same things but is slightly different ways.

I have never found cakes strict partitioning to be a problem in any
particular situation I can recall. This is likely to be because the
web is request based. Every time you will ever see a view rendered
that has to have been as the result of a request. And all requests go
through a Controller so you will always have access to Model data in
every request and the ability to pass that data to the view. Things
can be very different in a desktop application or something like a
Flash application in which the code runs continuously throughout the
"session". In these types of applications the MVC works a bit
differently.

I get the feeling from your question that you may be thinking too
strict in another way (as may seem to do). You are not limited to
locking the User model to the Users controller and the users views
only. I tend to think of the models on the one side and the controller
and view as a pair on the other. That is, the controller and view(s)
are tightly linked but the models can be utilised a bit more freely.

I would never render the Posts/index view from the Users controller
for example. But I would, and often do, access the Post model from the
Users controller and pass the data to the users views. To finally get
to some kind of point: Why would it be a problem to "get the list of
user clubs in the controller and pass it to the view" as you put it?
That is the primary purpose of the controller. It is essentially there
to interpret the request, access the model(s) and present that data to
the view. If you accessed the Models from the Views, the Controller
would not do much more than request routing.

I hope you are not offended by this accidental lecture on MVC. A topic
I am not an expert in by any stretch of the imagination. I was trying
to explain my limited knowledge of the reasoning behind the design of
CakePHP and to explain that there is more than one way to design an
MVC framework. You already mentioned yourself that you knew of a way
to access your data. I am afraid the "better" way you are looking for
is not "allowed". You could of-course probably set the whole Model
instance as a view variable but I have never tried that.




On Sep 24, 10:59 am, hunny <saurabh85maha...@gmail.com> wrote:
> Hi Guys,
>
> I am new to cakephp. I am having the following issue:
>
> I am displaying list of checkbox containing clubs to a login user. The
> list of clubs I am passing through the models via controllers in the
> traditional way.
>
> Now the logged in user should see his list of clubs automatically
> ticked. This list is present in another database.
>
> One solution is to get the list of user clubs in the controller itself
> and pass it to the view.
>
> But is there any alternative way, where I can access the user clubs in
> the view itself without loading in the controller.
>
> Basically i am looking for something similar like View Helpers in
> Zend. We can access the model data in views using view Helpers. Is
> there something similar in cakephp.
>
> P.S: I have asked this question to a few people who knew cake php and
> their first reaction is that you shouldn't access model data in views
> as it is against MVC. But let me assure you we can access model data
> in view as long as it is read only. At least that is what we are used
> to follow in Zend Framework. :)
--~--~---------~--~----~------------~-------~--~----~
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