2012-11-23 40 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/*文件。

相關問題