如何为我的两个模块创建两个不同的 404 页面
-
12-12-2019 - |
题
我需要为客户和供应商提供两个不同的 404 页面。
我需要为客户提供不同的页面,为供应商提供不同的页面。
我如何为客户和供应商制作不同的页面
解决方案
我建议您使用该事件 controller_action_layout_load_before
. 。通过设置您的事件来收听此内容,您应该能够使用 action
和 layout
与此事件相关的内容。
<events>
<controller_action_layout_load_before>
<observers>
<layout_test>
<class>layout_test/observer</class>
<method>changeLayoutEvent</method>
</layout_test>
</observers>
</controller_action_layout_load_before>
</events>
然后,您可以检查观察者中的操作类型,以确保您正在处理 404 页面,然后根据客户类型添加句柄。对于您来说,以下内容应该是一个好的开始:
$action = $observer->getEvent()->getAction();
if ($action instanceof Mage_Cms_IndexController && $action->getRequest()->getRequestedActionName() == 'noRoute') {
if (// Add check for customer or vendor here) {
$observer->getEvent()->getLayout()->getUpdate()
->addHandle('new_layout_handles');
}
}
然后,您只需为适当的句柄添加布局更新并根据需要更改模板/设计。
Varien_Event Object
(
[_observers:protected] => Varien_Event_Observer_Collection Object
(
[_observers:protected] => Array
(
)
)
[_data:protected] => Array
(
[action] => Mage_Cms_IndexController Object
(
[_currentArea:protected] => frontend
[_sessionNamespace:protected] => frontend
[_request:protected] => Mage_Core_Controller_Request_Http Object
(
[_originalPathInfo:protected] => /sales/order/hdsa/
[_storeCode:protected] =>
[_requestString:protected] => /sales/order/hdsa/
[_rewritedPathInfo:protected] =>
[_requestedRouteName:protected] =>
[_routingInfo:protected] => Array
(
)
[_route:protected] => cms
[_directFrontNames:protected] =>
[_controllerModule:protected] => Mage_Cms
[_isStraight:protected] =>
[_beforeForwardInfo:protected] => Array
(
)
[_paramSources:protected] => Array
(
[0] => _GET
[1] => _POST
)
[_requestUri:protected] => /amazoneclone/Web/index.php/sales/order/hdsa/
[_baseUrl:protected] => /amazoneclone/Web/index.php
[_basePath:protected] => /amazoneclone/Web
[_pathInfo:protected] => /sales/order/hdsa/
[_params:protected] => Array
(
)
[_rawBody:protected] =>
[_aliases:protected] => Array
(
)
[_dispatched:protected] => 1
[_module:protected] => cms
[_moduleKey:protected] => module
[_controller:protected] => index
[_controllerKey:protected] => controller
[_action:protected] => noRoute
[_actionKey:protected] => action
)
[_response:protected] => Mage_Core_Controller_Response_Http Object
(
[_body:protected] => Array
(
)
[_exceptions:protected] => Array
(
)
[_headers:protected] => Array
(
[0] => Array
(
[name] => Content-Type
[value] => text/html; charset=UTF-8
[replace] =>
)
[1] => Array
(
[name] => X-Frame-Options
[value] => SAMEORIGIN
[replace] => 1
)
[2] => Array
(
[name] => P3p
[value] => CP="CAO PSA OUR"
[replace] => 1
)
[3] => Array
(
[name] => Http/1.1
[value] => 404 Not Found
[replace] =>
)
[4] => Array
(
[name] => Status
[value] => 404 File not found
[replace] =>
)
)
[_headersRaw:protected] => Array
(
)
[_httpResponseCode:protected] => 200
[_isRedirect:protected] =>
[_renderExceptions:protected] =>
[headersSentThrowsException] => 1
)
[_realModuleName:protected] =>
[_flags:protected] => Array
(
)
[_cookieCheckActions:protected] => Array
(
)
[_isLayoutLoaded:protected] =>
[_titles:protected] => Array
(
)
[_removeDefaultTitle:protected] =>
)
[layout] => Mage_Core_Model_Layout Object
(
[_update:protected] => EM_Themeframework_Model_Layout_Update Object
(
[_elementClass:protected] =>
[_packageLayout:protected] =>
[_cacheId:protected] =>
[_cachePrefix:protected] =>
[_updates:protected] => Array
(
)
[_handles:protected] => Array
(
[default] => 1
[cms_page] => 1
[STORE_default] => 1
[THEME_frontend_default_em0117] => 1
[cms_index_noroute] => 1
[page_two_columns_right] => 1
)
[_subst:protected] => Array
(
[from] => Array
(
[0] => {{baseUrl}}
[1] => {{baseSecureUrl}}
)
[to] => Array
(
[0] => http://192.168.10.223/amazoneclone/Web/index.php/
[1] => http://192.168.10.223/amazoneclone/Web/index.php/
)
)
)
[_blocks:protected] => Array
(
)
[_output:protected] => Array
(
)
[_area:protected] => frontend
[_helpers:protected] => Array
(
)
[_directOutput:protected] =>
[_xml:protected] => Mage_Core_Model_Layout_Element Object
(
)
[_cacheId:protected] =>
[_cacheTags:protected] => Array
(
)
[_cacheLifetime:protected] =>
[_cacheChecksum:protected] =>
[_cacheSaved:protected] =>
[_cache:protected] =>
[_elementClass:protected] => Mage_Core_Model_Layout_Element
[_xpathExtends:protected] => //*[@extends]
)
[name] => controller_action_layout_load_before
)
[_hasDataChanges:protected] =>
[_origData:protected] =>
[_idFieldName:protected] =>
[_isDeleted:protected] =>
[_oldFieldsMap:protected] => Array
(
)
[_syncFieldsMap:protected] => Array
(
)
)