1

我正在尝试按照这个官方教程安装 yii-user 的扩展

http://www.yiiframework.com/extension/yii-user/#hh2

但我遇到了一些问题,特别是当我添加这个时

 user'=>array(
        // enable cookie-based authentication
        'class' => 'WebUser',
        'allowAutoLogin'=>true,
        'loginUrl' => array('/user/login'),

到配置主。当我添加此代码时,我收到此消息错误

包括(WebUser.php)[function.include]:无法打开流:没有这样的文件或目录

有什么线索吗?我需要先做点什么吗?

提前致谢

4

3 回答 3

5

我搜索了一下,我找到了解决方案。但它不在文档中。

因此,我们应该在protected/components中创建WebUser.php ,如下所示:

  <?php

// this file must be stored in:
// protected/components/WebUser.php

class WebUser extends CWebUser {

// Store model to not repeat query.
 private $UserLogin;

// Return first name.
// access it by Yii::app()->user->first_name
function getFirst_Name(){
$user = $this->loadUserLogin(Yii::app()->user->user_id);
return $user->first_name;
}  

// This is a function that checks the field 'role'
// in the User model to be equal to 1, that means it's admin
// access it by Yii::app()->user->isAdmin()
function isAdmin(){
$user = $this->loadUser(Yii::app()->user->user_id);
return intval($user->user_role_id) == 1;
}

// Load user model.
protected function loadUserLogin($id=null)
{
    if($this->UserLogin===null)
    {
        if($id!==null)
            $this->UserLogin=UserLogin::model()->findByPk($id);
    }
    return $this->UserLogin;
}
}?>

并且应该工作。

于 2012-11-23T15:27:08.713 回答
2

您是否按照http://www.yiiframework.com/extension/yii-user/#hh2上的说明进行操作?

您可能忘记指定用户模块的导入路径config.php

'import'=>array(
    ...
    'application.modules.user.models.*',
    'application.modules.user.components.*',
),
于 2012-11-23T12:33:17.577 回答
0

我有同样的问题,发现这是权限问题。Apache 用户(在我的情况下为 www-data)无法访问 protected/modules/users/* 文件。

于 2013-11-15T17:16:08.130 回答