2012-11-23 37 views
1

我试图下面这个官方教程警予用户的扩展包括:(WebUser.php)没有这样的文件或目录

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

安装警予用户的扩展,但我有一些问题,特别是当我加入这个

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

到配置为主。当我添加此代码,我有这个消息错误

包括(WebUser.php)[]:未能打开流:没有这样的文件或目录

任何线索?我需要做点什么吗?

在此先感谢

回答

5

我搜索一点点,我找到了解决办法。但它不在文档中。

所以,我们应该创造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; 
} 
}?> 

,并应工作。

+0

如果您尝试安装yii用户扩展,则不应创建自己的WebUser类。它已包含在用户/组件下的扩展中。 – jborch

+0

我下载的.rar文件没有.rar。但是,谢谢你的信息。 – unpix

0

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

相关问题