【问题标题】:Get Magento Session from Zend framework (Another Application)从 Zend 框架获取 Magento Session(另一个应用程序)
【发布时间】:2014-12-22 16:42:20
【问题描述】:

我想从 Zend 框架(另一个应用程序)获取 Magento 会话。我需要 Zend Framework 中的应用程序验证管理员中的用户是否已登录(Magento)。我的 Zend Framework 应用程序中有以下代码:

    // Initialize Magento
    include_once 'C:/xampp/htdocs/mymagento/app/Mage.php';

    // Initialize Magento
    Mage::app('default');

    // This initalizes the session, using 'adminhtml' as the session name.
    // Just ignore the returned Mage_Core_Model_Session instance
    Mage::getSingleton('core/session', array('name' => 'adminhtml'));

    // Get a singleton instance of the Mage_Admin_Model_Session class
    // This is just the 'admin' namespace of the current session. (adminhtml in this case)
    $session = Mage::getSingleton('admin/session');


    // Use the 'admin/session' object to check loggedIn status
    if ( $session->isLoggedIn() ) {
        echo "logged in";
    } else {
        echo "not logged in";
    }

响应总是“未登录”;当我登录 Magento 后端时。

【问题讨论】:

    标签: php magento zend-framework


    【解决方案1】:

    会话仅为父域创建 - 启动 Magento 的那个域。

    我假设在您的情况下 Magento 和“另一个 zend 应用程序”是不同的域,这可能会触发问题。 Magento 和“另一个 zend 应用程序”都应该在一个父域上。例如:

    (*.example.com | magento.example.com | anotherzendapp.example.com)。

    出现此问题的另一个原因是另一个 zend 应用程序的自动加载。如果是这种情况,这个解决方案应该会有所帮助:

    $autoloaders = spl_autoload_functions();
    $anotherZendApp = $autoloaders[0];
    spl_autoload_unregister($anotherZendApp);
    
    // YOU CODE
    
    restore_error_handler();
    restore_exception_handler();
    spl_autoload_register($anotherZendApp);
    

    【讨论】:

      猜你喜欢
      • 2011-07-17
      • 1970-01-01
      • 1970-01-01
      • 2017-06-27
      • 1970-01-01
      • 1970-01-01
      • 2016-12-06
      • 1970-01-01
      • 2011-09-09
      相关资源
      最近更新 更多