0

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!

alfizqu
  • 158
  • 1
  • 16

1 Answers1

3

What's wrong with a good old if?

<?php if ($theRoleOfTheUser == 'someSpecificRole') : ?>
    <div><?php echo $this->Form->input(…); ?></div>
<?php endif; ?>
deceze
  • 510,633
  • 85
  • 743
  • 889
  • OK! Thank you! I thought there would be a cakePHP method or something to deal with this, but actually this seems to work fine! I'm sorry, I'm learning PHP using cakePHP, at the same time. – alfizqu Jan 19 '11 at 14:44