Yii has a scene attribute (scenario) in the model, the document (www. yiiframework. comdocguide1.1zh _ cnform. model) indicates that if a block assignment is executed in the scenario, only the features that appear in the scenario verification rules will be assigned a block assignment, for example: {code ...}... yii has a scene attribute (scenario) in the model, the document (http://www.yiiframework.com/doc/guide/1.1/zh_cn/form.model) mentioned that if the block assignment is executed in the scene, only the features that appear in the scene validation rules will be assigned a value to the block, for example:
array('username, password', 'required', 'on'=>'login, register'),array('email', 'required', 'on'=>'register'),
If we perform block assignment in the login scenario, only username and password will be assigned a block assignment, because only these values will appear in the validation rules of the login scenario. If the scenario is register, these three features will be assigned a value to each block.
In actual applications, create a LoginForm model with three attributes: "username, password, and email", set the default value, and then execute the following in the controller:
$model = new LoginForm('login');$model->attributes = $_POST; // $_POST = array('username' => 'value', 'password' => 'value');
In this case, the $ model-> attributes attribute still contains all three attributes of the LoginForm model, I don't know how to obtain the attributes that are filtered by the validators and contain only the username and password keys, because I may need to insert these two fields into the database but do not need the email attribute, or I need to output these two attributes to the view and append them to the end of the URL parameter.
ConsultYii::app()->clientScript->registerCssFile
This method is used to call the custom insert position in the view. it is inserted before the title label by default, which is not very beautiful. In addition, the custom position may conflict with the plug-in or other styles.
Reply content:
Yii has a scene attribute (scenario) in the model, the document (http://www.yiiframework.com/doc/guide/1.1/zh_cn/form.model) mentioned that if the block assignment is executed in the scene, only the features that appear in the scene validation rules will be assigned a value to the block, for example:
array('username, password', 'required', 'on'=>'login, register'),array('email', 'required', 'on'=>'register'),
If we perform block assignment in the login scenario, only username and password will be assigned a block assignment, because only these values will appear in the validation rules of the login scenario. If the scenario is register, these three features will be assigned a value to each block.
In actual applications, create a LoginForm model with three attributes: "username, password, and email", set the default value, and then execute the following in the controller:
$model = new LoginForm('login');$model->attributes = $_POST; // $_POST = array('username' => 'value', 'password' => 'value');
In this case, the $ model-> attributes attribute still contains all three attributes of the LoginForm model, I don't know how to obtain the attributes that are filtered by the validators and contain only the username and password keys, because I may need to insert these two fields into the database but do not need the email attribute, or I need to output these two attributes to the view and append them to the end of the URL parameter.
ConsultYii::app()->clientScript->registerCssFile
This method is used to call the custom insert position in the view. it is inserted before the title label by default, which is not very beautiful. In addition, the custom position may conflict with the plug-in or other styles.
In this case, the $ model-> attributes attribute still contains all three attributes of the LoginForm model, I don't know how to obtain the attributes that are filtered by the validators and contain only the username and password keys, because I may need to insert these two fields into the database but do not need the email attribute.
Even if three attribute values are obtained, the scenario is verified.login
For other scenarios.
If you want to obtain two attribute values, refer to the following method.
//rulearray('username, password', 'required', 'on'=>'login, register'),array('email', 'required', 'on'=>'register'),
//controller$model = new LoginForm('login');$model->username= $_POST['username'];$model->username= $_POST['password']; // $_POST = array('username' => 'value', 'password' => 'value');
In practical applications, for example, editing and adding a form model for data verification (here we do not consider AR), one of the fields "field" is "1" by default ", this field is modified when a record is added.
If a record already exists in the database, a request to edit the record (POST does not contain the "field" field) is sent and verified using the form model,$model->attributes = $_POST
The attributes attribute contains the "field" field and the value is 1. if the attributes attribute is used for update, an error occurs.
In itself, the attributes attribute assignment is for convenience. if I have a large amount of data in the POST, the assignment will be too tired.
When the "validate ()" method is used for verification, only the features that appear in the verification rules of this scenario are verified. but how can we obtain the verified results?