我需要Magento 2x中的页面URL,包括我的自定义模块控制器中的密钥 . here类似的东西,但这是magento 1x . 我需要magento 2x .
对于magento 1x: Mage::helper('adminhtml')->getUrl('adminhtml/framexport/index') 但我需要类似的magento 2x .
Mage::helper('adminhtml')->getUrl('adminhtml/framexport/index')
您可以通过致电轻松获取管理员网址
$this->getUrl('adminhtml/module/action');
请不要在$ this对象中加载“Context”类型的对象
正确的方法是,在模型块或任何类构造函数中注入UrlInterface
然后调用getUrl()函数
class SomeClass extends \Some\Other\Class { protected $_backendUrl; public function __construct( ........... ........... \Magento\Backend\Model\UrlInterface $backendUrl, ........... ) { $this->_backendUrl = $backendUrl; } public function someFunction() { $params = array('some'=>'url_parameters'); $url = $this->_backendUrl->getUrl("the/url/path", $params); } }
您可以按如下方式获取管理员网址:
public function __construct(\Magento\Backend\Helper\Data $HelperBackend ) { $this->HelperBackend = $HelperBackend; } /** * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function getAdminUrl() { echo $this->HelperBackend->getHomePageUrl(); }
3 回答
您可以通过致电轻松获取管理员网址
请不要在$ this对象中加载“Context”类型的对象
正确的方法是,在模型块或任何类构造函数中注入UrlInterface
然后调用getUrl()函数
您可以按如下方式获取管理员网址: