View Single Post
  #4 (permalink)  
Old 04-24-2008, 11:31 PM
Mark^Bastard Mark^Bastard is offline
Junior Member
 
Join Date: May 2007
Posts: 15
Default

Quote:
Originally Posted by Elemental View Post
Any additional functionality you need in the view should be done in a view helper.

Ideally you should be performing all business/application logic before you get to the view. If you could give us some more info on why you need to get back to the controller perhaps we can help you clean up your design.
I most definitely agree with your comments.

Basically I'm creating an ACL admin screen that shows a matrix in a table. The rows are controller / action names, and the columns are group names. Each cell contains a checkbox indicating whether that group can access the action/controller on that row.

When initially rendering the page I need to have some boxes checked depending on the current access. For example user 'Admin' will have all of its boxes checked when the page loads.

I have assigned 'groups' and 'resources' arrays to the view and I'm looping through them to build the table. When creating the checkboxes I want to do something like:

<?php ($this->isAllowed($group, $controller, $action)) ? 'checked="checked" : '' ?>

So I can do this with a view helper, which may be a good idea as later on I may only want to show an 'edit' or 'delete' button on my pages based on the same isAllowed function.

At the moment I'm sending an array to the view, but it's very messy. The above becomes:

<?php ($this->aclMatrix[$group . '_' . $controller . '_' . $action] == 1) ? 'checked="checked" : '' ?>

I think view helper is the way to go. I have only just realised that it would be useful outside of this page, which was the deciding factor in using one.

For interests sake though, I'd like feedback still. There'd have to be some time where it makes sense to have a function that only one view needs access to.
Reply With Quote