2013-07-04 67 views
1

在應用主要配置:爲什麼Yii模塊找不到系統視圖?

'errorHandler'=>array(
    // use 'site/error' action to display errors 
    'errorAction'=>'site/default/error', 
), 

在/保護/模塊/網站/控制器/我有DefaultController.php用行動錯誤:

public function actionError() 
{ 
    if($error=Yii::app()->errorHandler->error) 
    { 
     if(Yii::app()->request->isAjaxRequest) 
      echo $error['message']; 
     else 
      $this->render('error', $error); 
    } 
} 

但是,如果我有錯誤,我看到它:

 
DefaultController cannot find the requested view "error". (/home/web/framework/web/CController.php:897)

0 /home/web/framework/web/CController.php(800): CController->renderPartial('error', Array, true) 1 /home/web/apps/myapp/protected/modules/site/controllers/SiteController.php(67): CController->render('error', Array) 2 /home/web/framework/web/actions/CInlineAction.php(50): SiteController->actionError() 3 /home/web/framework/web/CController.php(309): CInlineAction->runWithParams(Array) 4 /home/web/framework/web/CController.php(287): CController->runAction(Object(CInlineAction)) 5 /home/web/framework/web/CController.php(266): CController->runActionWithFilters(Object(CInlineAction), Array) 6 /home/web/framework/web/CWebApplication.php(283): CController->run('error') 7 /home/web/framework/base/CErrorHandler.php(332): CWebApplication->runController('site/site/error') 8 /home/web/framework/base/CErrorHandler.php(205): CErrorHandler->render('error', Array) 9 /home/web/framework/base/CErrorHandler.php(130): CErrorHandler->handleException(Object(CHttpException)) 10 /home/web/framework/base/CApplication.php(713): CErrorHandler->handle(Object(CExceptionEvent)) 11 [internal function]: CApplication->handleException(Object(CHttpException))

在Yii的文檔:

1.WebRoot /主題: 對應於一個視圖以下列順序視圖文件CErrorHandler搜索/ ThemeName/views/system:這是當前活動主題下的系統視圖目錄。

2.WebRoot/protected/views/system:這是應用程序的默認系統視圖目錄。

3.yii/framework/views:這是Yii框架提供的標準系統視圖目錄。

爲什麼Yii在使用模塊時在yii/framework/views中找不到視圖?

回答

1

錯誤處理程序需要作爲參數錯誤操作沒有錯誤查看

也錯誤信息是明確的,即DefaultController找不到視圖。

使用模塊時,將視圖放在模塊目錄中,而不是放在主要的yii視圖文件夾中。在你的情況下,錯誤視圖應該在/protected/modules/site/views/default/error.php,更一般地說:/protected/modules/<moduleId>/views/<controllerId>/<viewName>.php

要訪問根視圖,請使用//。從docs about view name resolving

Finds a view file based on its name. The view name can be in one of the following formats:

  • absolute view within a module: the view name starts with a single slash '/'. In this case, the view will be searched for under the currently active module's view path. If there is no active module, the view will be searched for under the application's view path.
  • absolute view within the application: the view name starts with double slashes '//'. In this case, the view will be searched for under the application's view path. This syntax has been available since version 1.1.3.
  • aliased view: the view name contains dots and refers to a path alias. The view file is determined by calling YiiBase::getPathOfAlias() . Note that aliased views cannot be themed because they can refer to a view file located at arbitrary places.
  • relative view: otherwise. Relative views will be searched for under the currently active controller's view path.

For absolute view and relative view, the corresponding view file is a PHP file whose name is the same as the view name. The file is located under a specified directory. This method will call CApplication::findLocalizedFile to search for a localized file, if any.

注意:這僅適用於控制器意見。

+0

我知道它,它的工作原理。但我很感興趣爲什麼我的問題(yii/framework/views)中的項目3在使用模塊時不起作用? –

+0

要訪問基本文件夾中的視圖,無論是否在模塊中,請使用雙斜槓啓動名稱'/ / – 2013-07-04 10:50:32

相關問題