show different views for different users with different permissions
i'm developing a social net like website and i have some trouble in how to manage views for different kind of users. i have several pages that it's开发者_如何学编程 content and resulting views depends on the users permissions. for example if user is a member of a group(has membership credential) can see so many things in that group page , but if he is not, the template should be so many different.
the simplest way is to control each part of the page with IF structure . but it's kind of nasty and i don't like it.
do you have any better idea or ifs are best solutions for these kind of situations.
thanks for your help.
It kind of depends on how you would like to create your templates. :-)
- Combine slots, partials and components. This is probably the easiest and most 'readable' solution. It separates the logic in easy reusable blocks.
- You could create seperate layouts, and call
<?php decorate_with('template_user'); ?>
in your template (add theif
-statements to a partial and include the partial) - or create your own base actions class, which in the
preExecute()
sets the template (this->setLayout('template_user')
) - Create separate actions, and forward the user based on it's permissions.
I'd go for the first :-)
精彩评论