Hello from Czech republic!
I’m just starting learning Yii and I came across following problem:
What is the best way to make small change in form (like "hide" one field)?
Example: I have standard Yii-generated user registration and login, and now I wanna change my user update action, so that it wouldn’t be possible to change username.
I have several ideas:
Example: I have standard Yii-generated user registration and login, and now I wanna change my user update action, so that it wouldn’t be possible to change username.
- Write something like
<?php
if (!$model->isNewRecord()) {
?>
...show username field...
<?php } ?>
in my views/user/_form.php
However, this solution doesn’t seem to be very “clean” to me, cause I think it’s not really strict MVC since I’m putting conditions into view.
-
Create _formUpdate.php and use different form for Update action. This doesn’t seem to be very good either because it means duplicated code (both _form.php and _formUpdate.php would be essentially the same, except for the one field).
-
Something similar like 2, except only have _formCreate.php with the first field and then include _form.php (which would have all fields except username). (Btw, what is the best way to do that? Can I use standard PhP include, or is there some mechanics for that in Yii?)
So, my question is, whether is there some better way how to achieve this with Yii? And if not, which way out of my three would you choose?
Thanks!