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;
parent::__construct($context);
}
public function execute()
{
$orderId = $this->request->getParam('order_id');
$order = $this->order->get($orderId);
if(!empty($order->getId())){
try {
$orderState = Order::STATE_COMPLETE;
$order->setState($orderState)->setStatus(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);
$resultRedirect->setUrl($this->_redirect->getRefererUrl());
return $resultRedirect;
}
}
i want to generate the url to redirect to this controller with magent 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: