3

So i have a controller to access form with structure like this:

Controller>Adminhtml>Preferences>NewAction.php

but when i try to acces /preferences/new, it gives me an error like this:

Fatal error: Uncaught TypeError: Argument 1 passed to Lime\Courier\Controller\Adminhtml\Preferences\NewAction::__construct() must be an instance of Magento\Backend\App\Action\Context, instance of Magento\Framework\ObjectManager\ObjectManager given, called in C:\xampp7\htdocs\magento2\vendor\magento\framework\ObjectManager\Factory\AbstractFactory.php on line 93 and defined in C:\xampp7\htdocs\magento2\app\code\Lime\Courier\Controller\Adminhtml\Preferences\NewAction.php:16 Stack trace: #0

here's my controller NewAction.php:

namespace Lime\Courier\Controller\Adminhtml\Preferences;
class NewAction extends \Lime\Courier\Controller\Adminhtml\Preferences
{
 protected $resultForwardFactory;
 /**
 * @param \Magento\Backend\App\Action\Context $context
 * @param \Magento\Framework\Registry $coreRegistry
 * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
 */
 public function __construct(
 \Magento\Backend\App\Action\Context $context,
 \Magento\Framework\Registry $coreRegistry,
 \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
 ) {
 $this->resultForwardFactory = $resultForwardFactory;
 parent::__construct($context, $coreRegistry);
 }
 /**
 * New action
 *
 * @return \Magento\Framework\Controller\ResultInterface
 */
 public function execute()
 {
 /** @var \Magento\Framework\Controller\Result\Forward $resultForward */
 $resultForward = $this->resultForwardFactory->create();
 return $resultForward->forward('edit');
 }
}
asked Jan 19, 2017 at 8:12
2
  • 1
    Remove var/generation folder? Commented Jan 19, 2017 at 8:13
  • 1
    Run php bin/magento setup:di:compile Commented Jan 19, 2017 at 8:13

1 Answer 1

5

As Magento compile the classes and put them in var/generation folder, So it will always be a better practice to delete var/generation and var/cache folder, whenever you created a new class or change any parameters of constructor of any class.

If you don't want to delete whole folder then try to delete files from the same class path from where you are getting error in generation folder, hopefully you will be able to debug the problem.

Another solution is to compile your code by setup:di:compile command but in developing phase it become cumbersome for developer to run this time taking command to just get a simple solution :) :)

answered Jan 19, 2017 at 8:40
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.