How in _form.php to determine whether we are in create or edit mode? (I need to make a filed not editable after the object was created.)
By the way would you suggest anything about how to implement non-editable (after created) fields?
How in _form.php to determine whether we are in create or edit mode? (I need to make a filed not editable after the object was created.)
By the way would you suggest anything about how to implement non-editable (after created) fields?
Using isNewRecord?
if ($model->isNewRecord) ....
The method described above is good. Just for learning purposes, I’ll mention that you can also pass a variable from the ‘parent’ view file which can serve as a flag symboling the information you seek. For example, in the controller action method create you pass another variable to the ‘create.php’ view file like this:
$this->render('create', array(..., 'is_create' => true));
And in the create.php view file when you render the ‘_form’ view file…:
echo $this->renderPartial('_form', array(..., 'is_create' => $is_create));
and you do the same in the update action method (but is_create there should be false) and view files… .
Again, this is more cumbersome, error prone and less maintainable than the first solution proposed above this one.