簡體   English   中英

未捕獲的異常“ Zend_Session_Exception”,帶有消息

[英]Uncaught exception 'Zend_Session_Exception' with message

當我在Zend Framework中運行Cron Job時,出現以下錯誤


Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Session must be started before any output has been sent to the browser; output started in /0' in /home/ZendFramework/library/Zend/Session.php:456 Stack trace: #0 /home/ZendFramework/library/Zend/Session/Namespace.php(143): Zend_Session::start(true) #1 /home/atypqapp/public_html/library/Plugins/AccessCheck.php(17): Zend_Session_Namespace->__construct('licence_error') #2 /home/atypqapp/public_html/application/modules/backend/Bootstrap.php(16): Plugins_AccessCheck->__construct(Object(Backend_Model_Libraryacl), Object(Zend_Auth)) #3 /home/ZendFramework/library/Zend/Application/Bootstrap/BootstrapAbstract.php(679): Backend_Bootstrap->_initAutoload() #4 /home/ZendFramework/library/Zend/Application/Bootstrap/BootstrapAbstract.php(632): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('autoload') #5 /home/ZendFramework/library/Zend/Application/Bootstrap/BootstrapAbstract.php(596): Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap(NULL) #6 in /home/ZendFramework/library/Zend/Session.php on line 456

這是我的庫>插件AccessCheck.php

class Plugins_AccessCheck extends Zend_Controller_Plugin_Abstract {

    private $_acl = null;
    private $_auth = null;

    public function __construct(Zend_Acl $acl, Zend_Auth $auth) {

        $this->_acl = $acl;
        $this->_auth = $auth;

        //*******************************
        // Checking License
        //******************************

        $licence_error = new Zend_Session_Namespace('licence_error');

        if (!$licence_error->active === NULL) {
            throw new Exception('Licence Error', 404);
        }

        // 
    }

    public function preDispatch(Zend_Controller_Request_Abstract $request) {


        parent::preDispatch($request);
        //  echo 'PRE DISPATCH';



        $resoruce = $this->_request->getControllerName();
        $action = $this->_request->getActionName();



        $identity = $this->_auth->getStorage()->read();

        //var_dump($identity);

        if (isset($identity)) {
            if (isset($identity->userID)) {
                //Load Adapter
                //  Zend_Registry::get("db");
                $previlages_db = new Backend_Model_Usersprofile();
                //get Role ID and find out the name of role

                $previlages_db_results = $previlages_db->loadProfileIDsSpecificUser($identity->userID);
                //  var_dump($identity->userID);

                $roles = array();

                foreach ($previlages_db_results as $value) {
                    array_push($roles, $value['profile_name']);

                    //var_dump($this->_acl->isAllowed($value['profile_name'], $resoruce, $action));
                    if (!$this->_acl->isAllowed($value['profile_name'], $resoruce, $action)) {
                        $request->setModuleName('public');
                        $request->setControllerName('unauthorized');
                        $request->setActionName('index');
                    } else {
                        //If one profile is OK,Give Permission To Access Particular Resources
                        break;
                    }
                }
                // var_dump($roles);
                // echo 'Allowed or not *******************************';
            }
        } else if (!defined('_CRONJOB_') || _CRONJOB_ == false) {
             //Load Adapter
                //  Zend_Registry::get("db");
                $previlages_db = new Backend_Model_Usersprofile();
                //get Role ID and find out the name of role

                $previlages_db_results = $previlages_db->loadProfileIDsSpecificUser($identity->userID);


                $roles = array();

            foreach ($previlages_db_results as $value) {
                    array_push($roles, $value['profile_name']);                   
                    if (!$this->_acl->isAllowed($value['profile_name'], $resoruce, $action)) {
                        $request->setModuleName('public');
                        $request->setControllerName('unauthorized');
                        $request->setActionName('index');
                    } else {
                        //If one profile is OK,Give Permission To Access Particular Resources
                        break;
                    }
            }

        }
        if ($this->_request->isXmlHttpRequest()) {
            if (!$this->_acl->isAllowed($value['profile_name'], $resoruce, $action)) {
                $request->setModuleName('public');
                $request->setControllerName('unauthorized');
                $request->setActionName('index');
            }
        }
    }

}

您需要在應用程序中更早地開始會話。 從堆棧跟蹤中,我可以看到您正在調用擴展BootstrapAbstract的后端引導程序文件。 要解決此錯誤,您可以在該文件中初始化會話。 請注意,引導文件中的任何_init方法都會自動調用。

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initSession()
    {
        // do any extra session config here
        Zend_Session::start();
    }
}

嘗試移動你的代碼有關在會議routeStartup在功能Plugins_AccessCheck這樣的類:

public function routeStartup(Zend_Controller_Request_Abstract $request)
{        
    //*******************************
    // Checking License
    //******************************

    $licence_error = new Zend_Session_Namespace('licence_error');

    if (!$licence_error->active === NULL) {
        throw new Exception('Licence Error', 404);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM