doucan8521 2013-07-04 09:51
浏览 220
已采纳

为什么Yii模块找不到系统视图?

In app main config:

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

In /protected/modules/site/controllers/ I have DefaultController.php with action error:

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

But if I have error, I see it:

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)) In Yii documentation: CErrorHandler searches for the view file corresponding to a view in the following order:

1.WebRoot/themes/ThemeName/views/system: this is the system view directory under the currently active theme.

2.WebRoot/protected/views/system: this is the default system view directory for an application.

3.yii/framework/views: this is the standard system view directory provided by the Yii framework.

Why Yii not find views in yii/framework/views when using modules ?

  • 写回答

1条回答 默认 最新

  • dongpao5127 2013-07-04 10:18
    关注

    Error handler takes as param error action not error view.

    Also error message is clear, that DefaultController cannot find view.

    When using modules, place views in module directory, not in main yii view folder. In your case error view should be in /protected/modules/site/views/default/error.php, more generally: /protected/modules/<moduleId>/views/<controllerId>/<viewName>.php

    To access root view, use //. From 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.

    NOTE: This applies only to controller views.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向