0

I am following Alan Storm's tutorial and am getting an error

Controller:

<?php
namespace Pulsestorm\HelloWorldMVVM\Controller\Hello;
use Magento\Framework\View\Result\PageFactory;
use Magento\Framework\App\Action\Context;
class World extends \Magento\Framework\App\Action\Action
{
    protected $pageFactory;
    public function __construct(Context $context, PageFactory $pageFactory)
    {
        $this->pageFactory = $pageFactory;
        return parent::__construct($context);
    }

    public function execute()
    {
        var_dump(__METHOD__);
        $page_object = $this->pageFactory->create();;
        return $page_object;
    }
}

Error:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function Pulsestorm\HelloWorldMVVM\Controller\Hello\World::__construct(), 1 passed in /var/www/html/generated/code/Pulsestorm/HelloWorldMVVM/Controller/Hello/World/Interceptor.php on line 14 and exactly 2 expected in /var/www/html/app/code/Pulsestorm/HelloWorldMVVM/Controller/Hello/World.php:9 Stack trace: #0 /var/www/html/generated/code/Pulsestorm/HelloWorldMVVM/Controller/Hello/World/Interceptor.php(14): Pulsestorm\HelloWorldMVVM\Controller\Hello\World->__construct(Object(Magento\Framework\App\Action\Context)) #1 /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(111): Pulsestorm\HelloWorldMVVM\Controller\Hello\World\Interceptor->__construct(Object(Magento\Framework\App\Action\Context)) #2 /var/www/html/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php(66): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('Pulsestorm\\Hell...', Array) #3 /var/www/html/vendor/magento/framework/ObjectManager in /var/www/html/app/code/Pulsestorm/HelloWorldMVVM/Controller/Hello/World.php on line 9
  • can you please add all the code of your controller file? – Abhishek Panchal Jan 18 '18 at 21:43
  • yes, this is the full code, it is one of the steps in the tutorial – Avremel Kaminetzky Jan 18 '18 at 21:44
  • mistake, let me correct it – Avremel Kaminetzky Jan 18 '18 at 21:46
  • something was wrong with stack exchange code formatting – Avremel Kaminetzky Jan 18 '18 at 21:47
  • please see my answer and remove 1 semi colon. And try again – Abhishek Panchal Jan 18 '18 at 21:48
1

The full code your Controller file is something like below:

<?php

namespace Pulsestorm\HelloWorldMVVM\Controller\Hello;

use Magento\Framework\View\Result\PageFactory;

class World extends \Magento\Framework\App\Action\Action
{
    /**
     * @var PageFactory
     */
    protected $pageFactory;

    /**
     * @param \Magento\Framework\App\Action\Context $context
     * @param PageFactory $pageFactory
     */
    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        PageFactory $pageFactory
    ) {
        $this->pageFactory = $pageFactory;
        parent::__construct($context);
    }

    public function execute()
    {
        echo "Hello World"; exit;
    }
}

Note: in that tutorial $page_object = $this->pageFactory->create(); this line is having 2 semi colon. remove 1 from it. Run below commands in sequence.

php bin/magento cache:flush
php bin/magento cache:clean
php bin/magento setup:upgrade
bin/magento setup:di:compile
From magento root directory: chmod -R 777 var/*
1

Just kill magento_root/var/generation and magento_root/var/di or magento_root/generated if you use 2.2 version and clear cache. Don't forget to leave .htaccess files in that folders.

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.