2011-11-19 90 views
1

我是新來的美麗的Yii框架。所以我只是閱讀教程和文檔。所以我從開始做博客教程。因此,對於博客應用程序,我將數據庫從Yii附帶的博客文件夾導出到MySQL。我再次決定使用Yii用戶模塊,爲此我將用戶模塊數據庫導出到MySQL。現在我的問題是,當我在應用程序中使用的登錄它顯示像這樣在YII框架中登錄錯誤

Trying to get property of non-object 

我都試過index.php?r=site/login,也index.php?r=user/login都失敗了一些錯誤。那麼有人能告訴我如何解決這個問題。 FYI在我的數據庫中有兩個字段,如從博客文件夾導入的'ia_user'和從Yii用戶模塊文件夾導入的'ia_users'。那麼是否有任何錯誤。下面我粘貼main.php文件的配置。

<?php 

// uncomment the following to define a path alias 
// Yii::setPathOfAlias('local','path/to/local-folder'); 

// This is the main Web application configuration. Any writable 
// CWebApplication properties can be configured here. 
return array(
    'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..', 
    'name'=>'My Blog Application', 

    // preloading 'log' component 
    'preload'=>array('log'), 

    // autoloading model and component classes 
    'import'=>array(
    'application.models.*', 
    'application.components.*', 
    /*user module starts here*/ 
    'application.modules.user.models.*', 
    'application.modules.user.components.*', 
    /*user module ends here*/ 
), 

    'modules'=>array(
    // uncomment the following to enable the Gii tool 
    /* 
    'gii'=>array(
     'class'=>'system.gii.GiiModule', 
     'password'=>'Enter Your Password Here', 
     // If removed, Gii defaults to localhost only. Edit carefully to taste. 
     'ipFilters'=>array('127.0.0.1','::1'), 
    ), 
    */ 
), 

    // application components 
    'components'=>array(
    'user'=>array(
     // enable cookie-based authentication 
     'allowAutoLogin'=>true, 
     /*user module starts here*/ 
     'loginUrl' => array('/user/login'), 
     /*user module ends here*/ 
    ), 
    // uncomment the following to enable URLs in path-format 
    /* 
    'urlManager'=>array(
     'urlFormat'=>'path', 
     'rules'=>array(
     '<controller:\w+>/<id:\d+>'=>'<controller>/view', 
     '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', 
     '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', 
    ), 
    ), 
    */ 
    //'db'=>array(
    // 'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db', 
    //), 
    // uncomment the following to use a MySQL database 

    'db'=>array(
     'connectionString' => 'mysql:host=localhost;dbname=tbl_blog', 
     'emulatePrepare' => true, 
     'username' => 'root', 
     'password' => 'root', 
     'charset' => 'utf8', 
     'tablePrefix'=> 'tbl_', 
    ), 

    'errorHandler'=>array(
     // use 'site/error' action to display errors 
      'errorAction'=>'site/error', 
     ), 
    'log'=>array(
     'class'=>'CLogRouter', 
     'routes'=>array(
     array(
      'class'=>'CFileLogRoute', 
      'levels'=>'error, warning', 
     ), 
     // uncomment the following to show log messages on web pages 
     /* 
     array(
      'class'=>'CWebLogRoute', 
     ), 
     */ 
    ), 
    ), 
), 

    // application-level parameters that can be accessed 
    // using Yii::app()->params['paramName'] 
    'params'=>array(
    // this is used in contact page 
    'adminEmail'=>'[email protected]', 
), 
); 

請幫我out.Any幫助和建議將成爲高度appreciable.I要求從Yii的論壇上的幫助,但沒有得到任何答覆所以我要求幫助這裏。

+0

我真的知道_nothing_這個框架,但我在config看到這一點:'/ *用戶模塊從這裏開始* /「loginUrl」 => array('/ user/login'),',也許你可以試試:index.php?r =/user/login - 但超越那個好運! –

+2

您看到的錯誤應該有一個文件名和行。查看該代碼,找到錯誤。然後繼續找到那個地方,那個錯誤的原因是什麼。修復原因。這就是所謂的調試,你在問題中發佈的代碼只是你網站的一小部分,所以很難說。請參閱[嘗試獲取非對象的屬性](http://stackoverflow.com/questions/3304904/trying-to-get-property-of-non-object) – hakre

+0

嘗試替換loginUrl「/ user/login 「到」用戶/登錄「(沒有」/「符號)。並給出更具體的日誌消息,因爲你應該看到你無法獲得某個對象的屬性。 –

回答

0

我不得不模塊的陣列添加用戶就這樣

'user'=>array(
     'user' 
     // enable cookie-based authentication 
     'allowAutoLogin'=>true, 
     /*user module starts here*/ 
     'loginUrl' => array('/user/login'), 
     /*user module ends here*/ 
    ),