dregduc63699 2013-05-15 08:35
浏览 48
已采纳

Yii:在自定义类中运行方法时,意外调用CHttpSession :: close

strange problem here. Using Yii framework I have the following class

class HtmlTableUi
{
  public function __construct(CWebModule &$module,$data,$actions) 
  {
    //...code goes here...
  }

  protected function renderTable() 
  {
    //... code goes here ...
  }
}

I can call HtmlTableUi::renderTable() from instance of HtmlTableUi in SchedulerModule class which is the main class in a separate application module. My SchedulerModule.php file:

<?php

Yii::import('scheduler.components.HtmlTableUi');

class SchedulerModule extends CWebModule
{
    public function init()
    {
        parent::init();
    }

    public function beforeControllerAction($controller, $action)
    {
        return true;
    }


    public function printUI($data,$actions,$submitPath)
        {
        $ui = new HtmlTableUi($this,$data,$actions,$submitPath);
        $ui->renderTable();
    }
}

Here comes the tricky part - when I call SchudulerModule::printUI from view (index.php) this way

<?php
    $this->module->printUI($casino,$actions,null);
?>

the code flow goes through SchudulerModule::printUI until reaching the point where renderTable is invoked ($ui->renderTable();) and instead stepping at the first line inside the body of that method it, contrary to any logic and rules, surprisingly jumps to CHttpSession::close !!?

Notice the Call Stack before invoking renderTable

protected/modules/scheduler/SchedulerModule.php.SchedulerModule->printUI:153    
protected/modules/scheduler/views/default/index.php.require:21  
/home/default/workspace/src/vlt/web/yii-1.1.12.b600af/framework/web/CBaseController.php.CBaseController->renderInternal:127 
/home/default/workspace/src/vlt/web/yii-1.1.12.b600af/framework/web/CBaseController.php.CBaseController->renderFile:96  
/home/default/workspace/src/vlt/web/yii-1.1.12.b600af/framework/web/CController.php.CController->renderPartial:870  
/home/default/workspace/src/vlt/web/yii-1.1.12.b600af/framework/web/CController.php.CController->render:783 
protected/modules/scheduler/controllers/DefaultController.php.DefaultController->actionIndex:57 

and after:

/home/default/workspace/src/vlt/web/yii-1.1.12.b600af/framework/web/CHttpSession.php.CHttpSession->close:134    
/home/default/workspace/src/vlt/web/yii-1.1.12.b600af/framework/web/CHttpSession.php.SchedulerModule->printUI:0
protected/modules/scheduler/views/default/index.php.require:21  
/home/default/workspace/src/vlt/web/yii-1.1.12.b600af/framework/web/CBaseController.php.CBaseController->renderInternal:127 
/home/default/workspace/src/vlt/web/yii-1.1.12.b600af/framework/web/CBaseController.php.CBaseController->renderFile:96  
/home/default/workspace/src/vlt/web/yii-1.1.12.b600af/framework/web/CController.php.CController->renderPartial:870  
/home/default/workspace/src/vlt/web/yii-1.1.12.b600af/framework/web/CController.php.CController->render:783 
protected/modules/scheduler/controllers/DefaultController.php.DefaultController->actionIndex:57 

Has anyone had similar issue? Can anyone explain that behavior?

  • 写回答

1条回答 默认 最新

  • dpwuvfpu52502 2013-05-15 09:00
    关注

    I found the solution!!! The access modifier of renderTable is supposed to be public, not protected. This wrong somehow in Yii framework results in unexpected runtime behavior instead of compilation error.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度