我需要知道谁正在访问一个特定的路由被记录,如果它是一个客户或管理员用户,任何想法如何做到匹配功能控制器或路由?
自定义路由控制器代码:
class Ceicom_Boleto_Controller_Router extends Mage_Core_Controller_Varien_Router_Abstract
{
public function initControllerRouters($observer)
{
$front = $observer->getEvent()->getFront();
$boleto = new Ceicom_Boleto_Controller_Router();
$front->addRouter('boleto',$boleto);
}
public function match(Zend_Controller_Request_Http $request)
{
/*
if is admin and is logged
*/
Mage::app()->getFrontController()->getResponse()
->setRedirect("/boleto/admin/view/")
->sendResponse();
exit;
/*
if is user and is logged
*/
Mage::app()->getFrontController()->getResponse()
->setRedirect("/boleto/user/view/")
->sendResponse();
exit;
}
}
试试下面的代码:
class Ceicom_Boleto_Controller_Router extends Mage_Core_Controller_Varien_Router_Abstract
{
public function initControllerRouters($observer)
{
$front = $observer->getEvent()->getFront();
$boleto = new Ceicom_Boleto_Controller_Router();
$front->addRouter('boleto',$boleto);
}
public function match(Zend_Controller_Request_Http $request)
{
/*
if is admin and is logged
*/
//get the admin session
Mage::getSingleton('core/session', array('name'=>'adminhtml'));
//verify if the user is logged in to the backend
if(Mage::getSingleton('admin/session')->isLoggedIn()){
Mage::app()->getFrontController()->getResponse()
->setRedirect("/boleto/admin/view/")
->sendResponse();
exit;
}
/*
if is user and is logged
*/
if(Mage::getSingleton('customer/session')->isLoggedIn()){
Mage::app()->getFrontController()->getResponse()
->setRedirect("/boleto/user/view/")
->sendResponse();
exit;
}
}
}
希望这对你有帮助!祝你一切顺利!
看看@ Magento:检测admin是否在前端页面登录
$sesId = isset($_COOKIE['adminhtml']) ? $_COOKIE['adminhtml'] : false ;
$session = false;
if($sesId){
$session = Mage::getSingleton('core/resource_session')->read($sesId);
}
$loggedIn = false;
if($session)
{
if(stristr($session,'Mage_Admin_Model_User'))
{
$loggedIn = true;
}
}
var_dump($loggedIn);
假设您正在使用基于DB的会话