Question

I'm trying to create a custom controller, but i have been having this error returned every time I try to run the module.

Uncaught Error: Call to undefined method Magento\Framework\App\Action\Action::construct()

Which is weird knowing that i've followed the exact process of creating controllers.

I've also tried looking for a similar case around the internet, but wasn't successful.

Here are the codes ive made so far:

=> module.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Jaycroll_Test" setup_version="2.2.0">
</module>

=> routes.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">

=> Write.php (the controller)

namespace Jaycroll\Test\Controller\Index;

use \Magento\Framework\App\Action\Action;

class Write extends Action
{
  public function __construct( \Magento\Framework\App\Action\Context $context ) {
     return parent::construct( $context );
  }
  public function execute()
  {
        var_dump("test");
        die('test index');
  }
}

Currently running Magento 2.2 on developer mode. I can't simply run setup:di:compile as i need to modify the module from time to time (https://www.cadence-labs.com/2017/07/magento-2-run-setupdicompile/)

Was it helpful?

Solution

It is not parent::construct.

It should be parent::__construct

You missed to add the prefix: __.

OTHER TIPS

//check your namespace path Write.php file should be inside Jaycroll\Test\Controller\Index folder
namespace Jaycroll\Test\Controller\Index;

use \Magento\Framework\App\Action\Action;

class Write extends Action
{
  public function __construct( \Magento\Framework\App\Action\Context $context ) 
       //use this 
    return parent::__construct( $context );
    //instead of 
     //return parent::construct( $context );


  }
  public function execute()
  {
        var_dump("test");
        die('test index');
  }
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top