Find us on facebook

Oct 12, 2013

Dealing with Forms in Yii

There are 3 major steps for dealing with forms.


  1. Create model class.
  2. Create a Controller action.
  3. Create form.
Create model class


There are two types of models.
  • Form Model - With this we can collect, use and discard user input. (Eg : Login form)
  • Active Record - With this we can collect user input and save them to the database.
Create a Controller action

Once model class is created, we should write code for the controller action to manipulate the model.

Create Form

Finally we create the form which contains HTML input fields. With Yii we can use helper classes to create forms.

Eg:  CHtml::textField() - we can call this to create text input field.
      CHtml::dropDownList() - we can call this to create drop down list.

No comments:

Post a Comment