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.

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

报告相同问题?

悬赏问题

  • ¥15 nslt的可用模型,或者其他可以进行推理的现有模型
  • ¥15 arduino上连sim900a实现连接mqtt服务器
  • ¥15 vncviewer7.0安装后如何正确注册License许可证,激活使用
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并2
  • ¥66 关于人体营养与饮食规划的线性规划模型
  • ¥15 基于深度学习的快递面单识别系统
  • ¥15 Multisim仿真设计地铁到站提醒电路
  • ¥15 怎么用一个500W电源给5台60W的电脑供电
  • ¥15 请推荐一个轻量级规则引擎,配合流程引擎使用,规则引擎负责判断出符合规则的流程引擎模板id
  • ¥15 Excel表只有年月怎么计算年龄