Skip to main content

Posts

Showing posts from April 25, 2014

Yii Forms Basic Tips

Whether the model extends CFormModel or CActiveRecord, the important thing to remember is that the form is tied to a model. This is significant because it’s the model that dictates what form elements should exist, controls validation of the form data, and even defines the form’s labels (e.g., “First Name” for the firstName attribute), and so forth. When you use Gii to auto-generate CRUD functionality for a model, the framework creates a form for you in a file named _form.php. Any view file in Yii that starts with an underscore is intended to be an include. Naturally, the controller dictates which primary view file gets rendered. Also understand that the same _form.php file is intended to be used whether the form is for creating new records or updating existing ones. Yii will take care of populating the form’s elements with the model’s current value when an update is being performed. Because forms are normally tied to models, you’ll need access to a model instance when you go to crea...