最近在学习php 一个流行的框架yii,听说封装得很好,但是在学习过程中也遇到了一些问题,先总结如下:
(1)The table "{{tbl_user}}" for active record class "User" cannot be found in the database.
详细错误:
错误原因:实体类User 的方法tableName 返回的是“'{{tbl_user}}'”
/**
* @return string the associated database table name
*/
public function tableName()
{
return '{{tbl_user}}';
}
但是在应用配置文件(D:\study\yii\yii\demos\shop_goods\protected\config\main.php)中,没有指定tablePrefix 。
解决方法:
方法一:去掉两边的花括号,改为:
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'tbl_user';
}
方法二:在应用配置文件(D:\study\yii\yii\demos\shop_goods\protected\config\main.php)中指定
tablePrefix
(2)使用CPasswordHelper::verifyPassword($password,$this->password); 有问题
return CPasswordHelper::verifyPassword($password,$this->password); 有问题,
返回false,但是实际上$password,$this->password 是相等。
(3)php中调用成员变量时使用->,而不是.
有java工作经验的开发者,在使用yii框架时非常容易使用. 来引用成员变量,这是java的语法,不是php的语法。
(4)对于注册页面,在对应的controller的action方法中,会使用$_POST['RegisterForm'] 来获取表单输入项的值,那么$_POST中的属性名(如RegisterForm)是由什么决定的呢?
是由render方法的第二个参数决定的
public function rules()
{
return array(
// username and password are required
array('username, password', 'required','on'=>'register,login'),
array('repassword', 'required','on'=>'register'),
// rememberMe needs to be a boolean
array('rememberMe', 'boolean','on'=>'login'),
// password needs to be authenticated
array('password', 'authenticate','on'=>'login'),
// 在注册场景中,密码repassword 必须和password 一致。
array('repassword', 'compare', 'compareAttribute'=>'password', 'on'=>'register'),
);
} (8)include(authenticate.php): failed to open stream: No such file or directory
有问题的代码: