开发者

Showing an input in a view depending on role

开发者 https://www.devze.com 2023-02-05 17:54 出处:网络
I have a fat view (add) with a lot of inputs (it\'s a form). For a role , there is a user_id input that is necessary, but for another role it isn\'t necessary. Here it comes my question, I know that

I have a fat view (add) with a lot of inputs (it's a form).

For a role , there is a user_id input that is necessary, but for another role it isn't necessary. Here it comes my question, I know that elements are used for this kind of things, but I would be duplicating a lot of code if I make a view with this input and another one without it. Is there any way to just replace a line of code depending on the role? H开发者_Go百科ow would it be?

Thank you very much in advance, have a nice day!


What's wrong with a good old if?

<?php if ($theRoleOfTheUser == 'someSpecificRole') : ?>
    <div><?php echo $this->Form->input(…); ?></div>
<?php endif; ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消