我编写了一个模块,它的行为应该与内联翻译相同:
如果我是管理员而且我已登录,我可以在前端看到一些特别的内容.但如果我不是管理员,那么我什么也看不见.
如何让模块知道在前端区管理员登录?
更新1
为了澄清一些我想描述的模块行为:
后端 - 只需保存配置一个值的表单.
前端 - 观察者,正在与一个事件挂钩.在Observer的功能中,我需要检查是否
当前前端用户登录到adminpanel,换句话说用户观看前端是admin.
因为通过此检查,我想向管理员用户提供一些基于前端更改的功能.
更新2
问题是我在前端有以下会话($ _ SESSION)转储:
[core] => Array ( [_session_validator_data] => Array ( [remote_addr] => ... [http_via] => [http_x_forwarded_for] => [http_user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0.1) Gecko/20100101 Firefox/8.0.1 ) [session_hosts] => Array ( [...] => 1 ) [messages] => Mage_Core_Model_Message_Collection Object ( [_messages:protected] => Array ( ) [_lastAddedMessage:protected] => ) [just_voted_poll] => [visitor_data] => Array ( [] => [server_addr] => ... [remote_addr] => ... [http_secure] => [http_host] => ... [http_user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0.1) Gecko/20100101 Firefox/8.0.1 [http_accept_language] => ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3 [http_accept_charset] => windows-1251,utf-8;q=0.7,*;q=0.7 [request_uri] => ... [session_id] => bb397df22a3410ccb07e567cb0333985 [http_referer] => ... [first_visit_at] => 2011-12-01 09:17:48 [is_new_visitor] => [last_visit_at] => 2011-12-01 13:21:38 [visitor_id] => 1536 [last_url_id] => 2408 ) [last_url] => ... ) [admin] => Array ( [_session_validator_data] => Array ( [remote_addr] => ... [http_via] => [http_x_forwarded_for] => [http_user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0.1) Gecko/20100101 Firefox/8.0.1 ) [session_hosts] => Array ( [...] => 1 ) ) [adminhtml] => Array ( [_session_validator_data] => Array ( [remote_addr] => ... [http_via] => [http_x_forwarded_for] => [http_user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0.1) Gecko/20100101 Firefox/8.0.1 ) [session_hosts] => Array ( [...] => 1 ) )
也许没有办法从前端访问管理员用户.好吧,我尝试通过Cookies.
我需要在控制器中执行此操作,特别是preDispatch()
方法,我认为这是一个明智的用例.
// Ensure we're in the admin session namespace for checking the admin user.. Mage::getSingleton('core/session', array('name' => 'adminhtml'))->start(); $admin_logged_in = Mage::getSingleton('admin/session', array('name' => 'adminhtml'))->isLoggedIn(); // ..get back to the original. Mage::getSingleton('core/session', array('name' => $this->_sessionNamespace))->start();