On 20 January 2011 11:26, Bernhard Schussek <[email protected]> wrote:
> 2011/1/20 Dan Leech <[email protected]>:
>> On a similar note, yesterday, to facilitate displaying certain fields
>> depending on the users security roles, I injected the security.context
>> into the constructor of the form in the DIC (best practice??). But
>> overloading the constructor was a little cumbersome, and I would
>> rather have set the `security.context` via. a method call.
>
> Can you show me some code?
For the form:
class UserCreateForm extends BaseUserForm
{
protected $securityContext;
public function __construct($name, $data = null,
ValidatorInterface $validator = null, $securityContext)
{
$this->securityContext = $securityContext;
parent::__construct($name, $data, $validator);
}
public function configure()
{
parent::configure();
$this->add(new CheckboxField('enabled'));
if ($this->securityContext->vote(User::ROLE_SUPERADMIN)) {
$this->add(new CheckboxField('superAdmin'));
}
if ($this->securityContext->vote(User::ROLE_COMPANYADMIN)) {
$this->add(new CheckboxField('companyAdmin'));
}
}
}
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en