-- tony stamp <[EMAIL PROTECTED]> wrote
(on Saturday, 26 July 2008, 05:32 AM -0700):
> I am thinking on rewriting a large form using zend_form. There is, however,
> an aspect that i need to consider, which is that in my application there are
> many different "levels" of user. There is a check on each form element to
> see if the user has the required level to be able to view the current form
> element. At the moment this is just a simple array / key check in a
> function, but i was wondering how to do this with zend_form - would i need
> to create a decorator, validator, filter? Then, how can i assign a user
> privilege to each form element within zend_form?
I would create a custom form class that does the checks as it is adding
elements to the form; if the user does not have privileges for a
particular element, you do not add it.
class FooForm extends Zend_Form
{
public function init()
{
$acl = Zend_Registry::get('acl');
$user = Zend_Auth::getInstance()->getIdentity();
if ($acl->isAllowed($user, 'FooForm', 'someoption')) {
$this->addElement('checkbox', 'someoption');
}
// etc...
}
}
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend Framework | http://framework.zend.com/