在Magento的很多地方,您都会遇到getUrl()的用法,它生成一个web地址。
它只需要两个参数,但非常常用的。
route 路由路径遵循”module/controller/action”的Zend行为。
module 模块部分是自动触发的。例如,“cms”解析为Mage_Cms。
controller 控制器是处理地址的类。“cms/page”指的是类Mage_Cms_PageController。
最后,action是该类中的方法。“cms /页面/视图”将callMage_Cms_PageController:: viewAction ()。
如果这些部件中的任何一个被指定为“*”,它将使用当前模块、控制器或正在使用的操作。如果省略,默认为“index”。
例如;如果查看CMS页面,下面的内容相当于“CMS /page/index”。
- Mage::getUrl(‘*/*’);
- // http://www.example.com/cms/page/
不被识别的部分被逐字传递,这是一个简单的捷径。您可以将路径传递到静态文件,并将其附加到域。
- Mage::getUrl(‘index.html’);
- // http://www.example.com/index.html
这是一个数组,它将key/value转换为路径目录对。
- Mage::getUrl(‘cms/page/view’, array(‘id’ => 1));
- // http://www.example.com/cms/page/view/id/1
有几个影响结果的特殊值。它们都以下划线开头并保留。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | KEY TYPE DESCRIPTION _current bool Uses the current module, controller, action and parameters _escape bool Uses & instead of & _forced_secure bool Uses the secure domain given in configuration _ignore_category bool Only applies to Mage_Catalog_Model_Product_Url::getUrl(). Prevents category rewrite from being used. _nosid bool Prevents a SID query parameter being used when referencing another store _secure bool Uses the secure domain if allowed in configuration _store_to_url bool Adds ___store to the query parameters. Useful for targetting a store that doesn’t have an unique domain. _use_rewrite bool Looks up the module/controller/action/parameters in the database for a search engine friendly equivalent. _store int or string Either the numeric store ID or textual store code. It will use the correct domain as the base URL. _absolute n/a No effect. URLs are always generated as absolute. _direct string Simply append to the base URL, same effect as passing to $routePath. _fragment string The last part of the URL after a # _type string link is the default. direct_link is useful for bypassing the “store code in URLs” feature. js,media and skin append the domain (and possibly store code) with the relevant directory. _query string or array If an array it is converted into a string like ?key=value&key=value which will become the$_GET variable. |
1 2 3 4 5 6 | Current Page Mage::getUrl('', array( '_current' => true, '_use_rewrite' => true )); |
1 2 3 4 5 6 7 8 9 | Current Page, Secured, For Another Store Mage::getUrl('', array( '_current' => true, '_use_rewrite' => true, '_secure' => true, '_store' => 2, '_store_to_url' => true )); |
1 2 3 4 5 6 7 | Static Page On Main Store Mage::getUrl('example.html', array( '_nosid' => true, '_store' => 'default', '_type' => 'direct_link' )); |
希望对你有帮助,以后多多关注SKY8G网站,有不懂得地方请留言。
文章不错非常喜欢