Showing an input in a view depending on role
-
12-10-2019 - |
Question
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? How would it be?
Thank you very much in advance, have a nice day!
Solution
What's wrong with a good old if
?
<?php if ($theRoleOfTheUser == 'someSpecificRole') : ?>
<div><?php echo $this->Form->input(…); ?></div>
<?php endif; ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow