Hello.
I am very new to Yii but have been developing enterprise apps in php for nearly a decade. Currently I am using a framework of my own design, that is very specific to my own needs. I am now interested in moving to a more generic framework so that I can concentrate more on application code and less on maintaining my own ORM / DB abstraction / MVC.
So, after much reading I have decided that Yii is very much at the forefront of the current crop of php frameworks. I have been evaluating the package by simply working through the yii-guide and determining how it fits with my workflow and that of my team. I have run into a question already with the CRUD generation done by Gii. My understanding is that the structure of the database is read in order to set up the rules for the input forms.
My database table is simple (actually provided by the tutorial). As you will see, I’ve configured mysql rather than sqllite.
[font="Courier New"]mysql> desc tbl_user;
±---------±-------------±-----±----±--------±---------------+
| Field | Type | Null | Key | Default | Extra |
±---------±-------------±-----±----±--------±---------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(128) | NO | | | |
| password | varchar(128) | NO | | | |
| email | varchar(128) | NO | | | |
±---------±-------------±-----±----±--------±---------------+[/font]
The code generated by Gii defining the input rules are as follows:
[font="Courier New"]public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('username, password, email', 'length', 'max'=>128),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, username, password, email', 'safe', 'on'=>'search'),
);
}[/font]
This code allows a new user to be created with no data at all. It appears that Gii missed the "NOT NULL" attributes of the editable fields.
I modified the rules as follows and the fields became required. (asterisks present on the create form and validation takes place upon submission. submission fails with empty fields)
[font="Courier New"]public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('username, password, email', 'length', 'max'=>128),
array('username, password, email', 'required'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, username, password, email', 'safe', 'on'=>'search'),
);
}[/font]
I have followed only the tutorial directions to run Gii and then did a bit of searching to determine how to add the "required" rule. This is an easy fix, but it seems that it should be unnecessary. Am I missing something here?
Thanks in advance for any replies!