I think my issue might have to do with dependency injection, which I'm still trying to grab the concept.
What I would like to do is to be able to get the URL using getUrl()
function from Magento\Framework\UrlInterface
object.
So this what I have so far.
- Create a functional controller and set up route. It is accessible via web browser and has
execute()
function defined. - Add use
Magento\Framework\UrlInterface
; in a controller class - Add a protected variable
$urlBuilder
Add a constructor like below
public function __construct( UrlInterface $urlBuilder ) { $this->urlBuilder = $urlBuilder; }
The follow error is thrown when I go to the URL that the controller is mapped to.
Fatal error: Uncaught TypeError: Argument 1 passed to Tester\ExamplePaymentGateway\Controller\Example\AbstractExample\Start::__construct() must implement interface Magento\Framework\UrlInterface, instance of Magento\Framework\App\Action\Context given, called in var/generation/Tester/ExamplePaymentGateway/Controller/Example/Start/Interceptor.php on line 14 and defined in app/code/Tester/ExamplePaymentGateway/Controller/Example/AbstractExample/Start.php:24
Stack trace:
#0 var/generation/Tester/ExamplePaymentGateway/Controller/Example/Start/Interceptor.php(14):
Tester\ExamplePaymentGateway\Controller\Example\AbstractExample\Start->__construct(Object(Magento\Framework\App\Action\Context), Object(Magento\Customer\Model\Session\Interceptor), Object(Magento\Checkout\Model\Session\Interceptor), Object(Magento\Sales\Model\OrderFactory), Object(Magento\Paypal\Model\Express\Checkout\Factory), Object(Magento\Framework\Session\Ge in app/code/Tester/ExamplePaymentGateway/Controller/Example/AbstractExample/Start.php on line 24
Am I missing some step before I can inject the URL builder or any other objects (let's say quote, cart, or payment helper)?
var/generation
?