0

Is there a way to call custom admin controller (which prints a pdf file from sales order view page) from frontend download anchor link?

<a href="http://m7.local/index.php/admin/magemechanic_workorder/order/print/order_id/<?php echo $orderId ?>" download>Download</a>

1 Answer 1

0

As per the updated question, no, you cannot configure Magento to invoke an adminhtml controller from the frontend for security reasons. Put the code in a class, and invoke that class from both the adminthml and frontend controllers separately.

Original answer to the original question regarding invoking one controller from another:

You can invoke a controller just like any other code. Use Dependency Injection to get an instance on your constructor, then invoke a method on that object.

<?php
namespace Vendor\Mod\Foo\Bar;

use Vendor\Mod\Controller\Adminhtml\Custom;

class Foobar {

    /** @var Custom */
    protected $_custom;

    public function __construct(Custom $custom)
    {
        $this->_custom = $custom;
    }


    public function foo()
    {
        $this->_custom->initPage();
    }

}
3
  • Thank you for the response. I want to call the controller on click of the anchor link. Please see my updated answer. Commented Aug 17, 2022 at 17:43
  • As per your updated question, no. Commented Aug 18, 2022 at 6:54
  • kindly can you take a look here magento.stackexchange.com/questions/359058/… Commented Aug 22, 2022 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.