Sorry for not replying to your previous post, I was a bit busy... This
looks related so here you go :)
On Wed, Jan 27, 2010 at 3:22 PM, Thomas Riché <thomas...@gmail.com> wrote:
> Hello,
>
> I have the following problem;
>
> I need to display a menu bar on all the pages of my app => I putted in place
> the according <div> in my base.html template.
> The thing is, the menu need to be different given the user, ie Anonymous get
> minimal menu, normal user get additional menu and admin get full menu.
>
> To achieve this, I created a Menu model, and store my menu in the DB, given
> a permission.
> I also create a Menu View that returns the list of menus according to the
> user rights.
A 'Menu' model sounds overkill according to what you want to achieve.
If you need to dynamically display a menu depending on the user's
role, here's what I would do :
- A view that looks like :
Pluf::loadFunction('Pluf_Shortcuts_RenderToResponse');
class App_Views {
public function index($request, $match) {
// do something useful, and then...
return Pluf_Shortcuts_RenderToResponse('sdoc/base.html',
array(), $request);
}
}
By default, the RenderToResponse will put the '$request->user'
attribute in the template context. Then, you will need in your
template:
<div id="menu">
<!-- items available to all roles -->
{if $user.isAnonymous()}
<!-- some menu items only for anonymous users -->
{else}
<!-- some other menu items for authenticated users -->
{/if}
{if $user.staff}
<!-- some menu items for administrators -->
{/if}
You could also use Pluf's permission system to do things like :
{if $user.has_perm('App.do_something_nasty')}
<!-- tell him he can do nasty things -->
{/if}
You'll probably have more detailed information about the permission
system in the thread you just started :)
Regards,
Bruno
> --
> You received this message because you are subscribed to the Google Groups
> "Pluf Users" group.
> To post to this group, send email to pluf-...@googlegroups.com.
> To unsubscribe from this group, send email to
> pluf-users+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pluf-users?hl=en.
>