I'm using Magento 2.2 in development mode.
I have a controller class
class MyController
{
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\Message\ManagerInterface $messageManager)
{
// stuff
}
}
That works correctly. However, if I add an additional constructor parameter like this:
class MyController
{
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Framework\Message\ManagerInterface $messageManager)
{
// stuff
}
}
I get the error
PHP Fatal error: Uncaught TypeError: Argument 2 passed to
Ben\Testing\Controller\Test::__construct() must be an instance of
Magento\Framework\View\Result\PageFactory, instance of
Magento\Framework\Message\ManagerInterface given, called in
/magento-dev/magento2/generated/code/Ben/Testing/Controller/Test/Interceptor.php
on line 7 and defined in /magento-dev/magento2/app/code/Ben/Testing/Controller/Test.php:7
...
If I clear the /generated
folder and refresh the page, it works.
My question is about how Magento handles caching and generated code. I can add additional code to non-constructor functions without needing to clear /generated
, and it works. Why does that work, but adding additional constructor parameters requires me to clear the /generated
folder?