Thursday, July 2, 2009

Struggeling with MVC and multiple views

Hi,

I seem to be struggeling with possibly something so obvious, i can't
find it in the tutorials or books. Hopefully someone here is able to
enlight me. I have made a good number of sites with PHP and just moved
to cakephp as a mvc framework. I completed the blog and auth/acl
tutorials. So far I like the speed of development, however I don't
seem to grasp how to properly create a page combining multiple views,
leaving the mvc framework (with auth in tact).

E.g. In the blog tutorial a simple blog is created based on a model
for post. This model has functions for view and add, in the blog
tutorial you either view posts or add a posts.

I would like to create a page that shows the last top 10 posts, AND an
add form to add posts when needed, as effectively as possible.

The way I ended up doing it is to change the index to display a form
for the add post, linking to add, and a seperate table viewing the
lasts posts. However I basically copied the code for the 'view.ctp'
and add.ctp', which means dublicate code. For this reason this does
not seem to be the proper way. Not only because I have dublicate code,
also because the add form is now visible to everyone while 'guests'
can't posts. (based on the ACL, guests should not be able to add
posts, only view them)

I would like to understand what best practice is to cover this in
cakePHP;
-> Create a page seperate from the models;
-> Create elements, in this case to show and add, that calls the
functions controller?
-> Use requestAction to call controller functions from within those
elements?

If someone whould have (a link to) an example that would be highly
appreciated.

Thanks in advanced for your response,

Reinder

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

No comments: