문제

I want to get URL like this after domain URL

domainname/hellowword/example-index
도움이 되었습니까?

해결책

Try This code

protected $_storeManager;

public function __construct(
    ..........................................................
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    ..........................................................
) {
    ..........................................................
    $this->_storeManager = $storeManager;
    ..........................................................
}

public function getCustomiseUrl()
{
    $url = $this->_storeManager->getStore()->getUrl('hellowword/example-index');
    //$url = $this->_storeManager->getStore()->getCurrentUrl();
    // get prase url
    $prse_url = parse_url($url);
    $get_url = '';
    if (isset($prse_url['host'])) {
        $get_url = $prse_url['host'];
    }
    if (isset($prse_url['path'])) {
        $get_url .= $prse_url['path'];
    }
    echo "get_url ".$get_url;
}

I Hope This Helps You.

다른 팁

You can try to create a custom router (https://devdocs.magento.com/guides/v2.4/extension-dev-guide/routing.html)

or create a URL redirect from the admin URL rewrites to point your hellowword/example-index to your action controller (https://docs.magento.com/user-guide/marketing/url-rewrite-custom.html)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top