I have a controller for adminhtml area like this:

namespace Namespace\Module\Controller\Adminhtml\Order;

use Magento\Framework\Controller\ResultFactory;
use Magento\Sales\Model\Order;

class Complete extends \Magento\Backend\App\Action
    protected $resultPageFactory;

    public function __construct(
        \Magento\Backend\App\Action\Context $context,
    \Magento\Sales\Api\OrderRepositoryInterface $order
    $this->order = $order;

    public function execute()
    $orderId = $this->request->getParam('order_id');
    $order = $this->order->get($orderId);
      try {
        $orderState = Order::STATE_COMPLETE;
        $this->messageManager->addSuccess(__("Successfully completed the order"));
      } catch (Exception $e) {
        $this->messageManager->addError(__("There's something wrong, please try again!"));
    } else {
      $this->messageManager->addError(__("Invalid Order"));
    $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
    return $resultRedirect;

i want to generate the url to redirect to this controller with magento GET parameter order_id, how to do it in block file, so i can get the url from my phtml?

edit: i tried to do it like this:

$url = $block->getUrl('mymodulerouter/order/complete', ['param' => array("order_id"=>$order->getId())]);

echo $url;

but the result only generate the url to the controller without request get parameter, like this:


  • what is your module etc/adminhtml routes.xml file frontname? Dec 27 '17 at 6:31

For multiple querystring variable

$params = [
    'order_id' => $block->getOrderId(),
    'website_id' => $block->getWebsiteId(),
$url = $block->getUrl('mymodulerouter/order/complete', $params)
echo $url;

For single variable,

$url = $block->getUrl('mymodulerouter/order/complete', ['order_id' => $order->getId()])
echo $url;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.