0

Getting below error -

Recoverable Error: Argument 1 passed to namespace\Modulename\Controller\Adminhtml\Blacklist\Index::_‌​_construct() must be an instance of Magento\Backend\App\Action\Context, instance of Magento\Framework\ObjectManager\ObjectManager given, called in /home/mage2demo/public_html/mage21new/vendor/magento/framewo‌​rk/ObjectManager/Fac‌​tory/AbstractFactory‌​.php on line 93 and defined in /home/mage2demo/public_html/mage21new/app/code/Namespace\Mod‌​ulename/Controller/A‌​dminhtml/Blacklist/i‌​ndex.php on line 13

here is the code -

namespace Mynamespace\Modulename\Controller\Adminhtml\ModuleDirectoryname;

use \Magento\Backend\App\Action;
use \Magento\Backend\App\Action\Context;

class Index extends Action
{
    protected $helper;
    protected $context;

    public function __construct(
        Context $context,
        \VT\Blacklist\Helper\Data $helper
    ) {
        $this->viewHelper = $viewHelper;
        parent::__construct($context);
    }

    public function execute()
    {
        echo "hello"; die;
    }
}

enter image description here

  • I tried by removing "var/generation" then again run upgrade n compile But result is same. – Atul Sep 1 '16 at 8:29
  • Could you post the content of namespace\Modulename\Controller\Adminhtml\Blacklist\Index.php please ? – Raphael at Digital Pianism Sep 1 '16 at 9:27
  • its above in after "here is the code" section... – Atul Sep 1 '16 at 9:34
0

Well first, your namespace is wrong. You should replace:

namespace Mynamespace\Modulename\Controller\Adminhtml\ModuleDirectoryname;

With:

namespace Mynamespace\Modulename\Controller\Adminhtml\Blacklist;

Then second problem is that you assign your helper to a variable that doesn't exist. Instead of:

$this->viewHelper = $viewHelper;

You should write:

$this->helper = $viewHelper;

But I highly doubt those two issues are the cause of your problem. I suggest you try declaring the Context class explicitely in your constructor.

So replace:

Context $context

With:

\Magento\Backend\App\Action\Context $context
  • here is the code - plz take review - ========================= namespace VT\Blacklist\Controller\Adminhtml\Blacklist; use \Magento\Backend\App\Action; use \Magento\Backend\App\Action\Context; class Index extends Action { protected $helper; protected $context; public function __construct( Context $context, \VT\Blacklist\Helper\Data $helper ) { $this->viewHelper = $helper; parent::__construct($context); } public function execute() { echo "hello"; die; } } – Atul Sep 1 '16 at 9:53
  • @Atul did you read my answer at all ? The code you pasted does not show any changes based on my answer – Raphael at Digital Pianism Sep 1 '16 at 9:54
  • brother I have made changes in code now . Plz check and let me know what I am still doing wrong - namespace VT\Blacklist\Controller\Adminhtml\Blacklist; use \Magento\Backend\App\Action; class Index extends Action { protected $helper; protected $context; public function __construct( \Magento\Backend\App\Action\Context $context, \VT\Blacklist\Helper\Data $helper ) { $this->helper = $helper; parent::__construct($context); } public function execute() { echo "hello"; die; } } – Atul Sep 1 '16 at 9:58
  • I just added the Controller file screenshot , plz check. After make upgrade and compile now its redirecting to dashboard. here is the URL - baseURL/admin/vt_blacklist/blacklist/index/key/… – Atul Sep 1 '16 at 10:13
0

You can try with below code, Replace $this->viewHelper = $viewHelper; with $this->viewHelper = $helper;

namespace Mynamespace\Modulename\Controller\Adminhtml\ModuleDirectoryname;

use \Magento\Backend\App\Action;
use \Magento\Backend\App\Action\Context;

class Index extends Action
{
    protected $viewHelper;
    protected $context;

    public function __construct(
        Context $context,
        \VT\Blacklist\Helper\Data $helper
    ) {
        $this->viewHelper = $helper;
        parent::__construct($context);
    }

    public function execute()
    {
        echo "hello"; die;
    }
}
  • i did the respective change but same error again. – Atul Sep 1 '16 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.