Php framework yii entry problems

Source: Internet
Author: User
Tags php framework
Php framework yii entry problems recently I have been studying a popular php framework yii. I have heard that it is well encapsulated, but I also encountered some problems during the learning process. The following is a summary :? (1) Thetable {tbl_user} foractiverecordclassUsercannotbefoundinthedatabase. Detailed error :? Cause of error: problems encountered when getting started with object class Us php framework yii

I recently learned about a popular php framework yii. I have heard that it is well encapsulated, but I also encountered some problems in the learning process. The following is a summary:

?

(1)The table "{tbl_user}" for active record class "User" cannot be found in the database.

Detailed error:

? Cause of error: the tableName method of the object class User returns "'{tbl_user }}'"

/** * @return string the associated database table name */public function tableName(){return '{{tbl_user}}';}

? However, no tablePrefix is specified in the application configuration file (D: \ study \ yii \ demos \ shop_goods \ protected \ config \ main. php.

Solution:

Method 1: Remove the curly braces on both sides and change:

/** * @return string the associated database table name */public function tableName(){return 'tbl_user';}

?

Method 2: In the application configuration file (D: \ study \ yii \ demos \ shop_goods \ protected \ config \ main. php), specify

TablePrefix

(2)Use CPasswordHelper: verifyPassword ($ password, $ this-> password );

Return CPasswordHelper: verifyPassword ($ password, $ this-> password); problem,
Returns false, but in fact $ password, $ this-> password is equal.

(3) used to call member variables in php->Instead.

Developers with java experience can easily reference member variables when using the yii Framework. this is a java syntax, not a php syntax.

?

(4) for the registration page, in the action method of the corresponding controller, $ _ POST ['registerform'] is used to obtain the value of the form input item, so what is the decision of the attribute name (such as RegisterForm) in $ _ POST?

YesbyRenderDetermined by the second parameter of the method

?

(5)How to differentiate scenarios

For example, you need to enter email and repassword during user registration, while you do not need to enter email and repassword during user logon. This means that the verification elements are different for different scenarios. How to implement it?

In RegisterForm's rules () method

public function rules(){return array(// username and password are requiredarray('username, password', 'required'),array('email,repassword', 'required','on'=>'register'),// rememberMe needs to be a booleanarray('rememberMe', 'boolean','on'=>'login'),// password needs to be authenticatedarray('password', 'authenticate','on'=>'login'),);}

? 'On' => 'register 'indicates that verification is only required in the "register" scenario.

So how to choose a scenario?

Specify

$ Model = new RegisterForm ('Register');

?

For example

Array ('username, password', 'required', 'on' => 'Login, register '),
Array ('email ', 'required', 'on' => 'register '),
As shown above, the username and password features are mandatory in the login scenario. The username, password, and email features are in the register field.
It is required in the scenario. Therefore, if we execute block assignment in the login scenario, only username and password will be assigned a block assignment. Because only it
In the login validation rules. On the other hand, if the scenario is register, all three features can be assigned a value.
// In The logon scenario
$ Model = new User ('login ');
If (isset ($ _ POST ['user'])
$ Model-> attributes = $ _ POST ['user'];
// In the registration scenario
$ Model = new User ('register ');
If (isset ($ _ POST ['user'])
$ Model-> attributes = $ _ POST ['user'];

?

? (6)How to obtain the input values of a form in batches

$ Model-> attributes = $ _ POST ['registerform'];

? After a class instance is created, we usually need to fill in its features with the data submitted by the end user. This can be done through the following block assignment (massive
Assignment:
$ Model = new LoginForm;
If (isset ($ _ POST ['loginform'])
$ Model-> attributes = $ _ POST ['loginform'];
The final expression is called a block value assignment (massive assignment ).Copy each item to the corresponding model features
Medium. This is equivalent to the following assignment method:
Foreach ($ _ POST ['loginform'] as $ name => $ value)
{
If ($ name is a secure feature)
$ Model-> $ name = $ value;
}

?

(7)How is * generated in the form?

Determined by the rules () method in $ model.

? We see no email*In RegisterForm, it is necessary that the rules () in RegisterForm is not bound to email.

Public function rules () {return array (// username and password are requiredarray ('username, password', 'required', 'on' => 'register, login '), array ('repassword', 'required', 'on' => 'register '), // rememberMe needs to be a booleanarray ('rememberme', 'boolean ', 'on' => 'login'), // password needs to be authenticatedarray ('password', 'authenticate', 'on' => 'login '), // in the registration scenario, the password repassword must be consistent with the password. Array ('repassword', 'Company', 'companyattribute '=> 'password', 'on' => 'register '),);}

?

?

(8) include (authenticate. php): failed to open stream: No such file or directory

Problematic code:

?

Cause: no authenticate () method is available

Just comment out 30.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.