Wednesday, July 29, 2009

Re: Struggeling with MVC and multiple views

Any further input on this would be appreciated. I have a very similar
question.

On Jul 5, 7:45 am, Reinder <reindervis...@gmail.com> wrote:
> Thanks for your response, however I don't think this solves theacl
> part of it, e.g. i would like to archive the following setup;
>
> main index page containing three elements, all with its ownacl
> management;
> ->Login form
>   ->If user is logged in show logout view (containing username +
> link), otherwise display standard login form.
> ->Add form
>   ->If user is logged in and allowed to add, show add form, otherwise
> display 'not able to edit message'
> ->View post table
>   ->Always display the last 10 posts.
>
> Does this mean I have to include access managements from within the
> templates or can I control this on the controller level?
>
> Thanks in advanced,
>
> Reinder
>
> On Jul 2, 6:30 pm, brian <bally.z...@gmail.com> wrote:
>
> > On Thu, Jul 2, 2009 at 7:39 AM, Reinder<reindervis...@gmail.com> wrote:
>
> > > 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 blogtutoriala simple blog is created based on a model
> > > for post. This model has functions for view and add, in the blog
> > >tutorialyou 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 theACL, 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
>
> > What I usually do for my forms is to put them in an element. So, for
> > Post model, I'd have in views/posts/add.ctp a line with
> > $this->element('posts/form'). And the file
> > views/elements/posts/form.ctp includes all of the logic for creating
> > the form, including whether to show an add or edit form, stuff for
> > admins only, etc.
>
> > switch ($this->params['action'])
> > {
> >         case 'edit':
> >                 echo $form->create('Post', array('action' => 'edit'));
> >                 echo $form->hidden('Post.id');
> >                 echo $form->hidden('Post.user_id');
> >         break;
>
> >         case 'add':
> >         default:
> >                 echo $form->create('Post', array('action' => 'add'));
> >                 echo $form->hidden('Post.user_id', array('value' => $user_id));
>
> > }
>
> > This way, you can include the form in your add or edit views, as well
> > as in your index view. Put a debug($this->params) in your view
> > somewhere to get an idea how that's set up.- Hide quoted text -
>
> > - Show quoted text -

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