Difference between #2 and #7 of
MVC primer and 5 minute form walkthrough

Changes

Title changed

SimpleMVC primer and 5 minute form walkthrough tutorial

Category unchanged

Tutorials

Yii version unchanged

Tags changed

Forms, tutorial, mvc

Content changed

[...]
When you come to create the form Yii will automatically create validation rules based on your table structure - so in the case below Yii won't validate a null title or a title which is more than 5 characters.

~~~
CREATE TABLE tbl_details (
     uniq VARCHAR(20) NOT NULL PRIMARY KEY,     date_in date DEFAULT NULL,     time_in time DEFAULT NULL,     title VARCHAR(5) NOT NULL,      first VARCHAR(30) DEFAULT NULL,     last VARCHAR(30) DEFAULT NULL,      email VARCHAR(60) DEFAULT NULL
);
~~~
[...]
Note, if Gii is unable to create the model it might be because your webserver process does not have the necessary permissions to write to the models folder.

It's worth noting here that you might want to modify the attributeLabels() method in your model.  Otherwise, when you come to create your form it will use the defaults listed here which are simply the tidied-up names of your database fields.
 
 
### **Step 3: Create a controller**
Now we have a model we need to create a controller. You can think of a controller as mediating between a model and a view.
[...]
- Your controller is using protected/views/layouts/column2.php to render your view (protected/views/your_controller/index.php)

### **Step 4: Create
the forma view**
Return to Gii and click on the 'Form Generator' link.
[...]
~~~

### **Step 5: View
ing the form**
Instead of rendering index.php, we might just want to view the form directly. Edit the following method in your DetailsController:
[...]
* Lists all models.
*/

 
public function actionIndex()         {              $model=new Details;              if(isset($_POST['Details']))             {   
 
                
{   
 
$model->attributes=$_POST['Details'];               if ($model->save())          { print "Your model has been saved";die();   }
 
        
 die();  
 
}
 
   
}   
 
$this->render('details_form',array(             'model'=>$model,         )); 
 
        
)); 
 
}
~~~

Visit the url below to view your form.

~~~
[...]
8 0
6 followers
Viewed: 29 501 times
Version: 1.1
Category: Tutorials
Written by: rix.rix.
Last updated by: rix.rix.
Created on: May 11, 2012
Last updated: 11 years ago
Update Article

Revisions

View all history