Php 从Zend framework获取Magento会话(另一个应用程序)
我想从Zend Framework(另一个应用程序)获取Magento会话。我需要Zend Framework中的应用程序验证管理员中的用户是否已登录(Magento)。我的Zend Framework应用程序中有以下代码:Php 从Zend framework获取Magento会话(另一个应用程序),php,magento,zend-framework,Php,Magento,Zend Framework,我想从Zend Framework(另一个应用程序)获取Magento会话。我需要Zend Framework中的应用程序验证管理员中的用户是否已登录(Magento)。我的Zend Framework应用程序中有以下代码: // Initialize Magento include_once 'C:/xampp/htdocs/mymagento/app/Mage.php'; // Initialize Magento Mage::app('default');
// 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后端时。该会话仅为父域创建-从中启动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);