Skip to main content
Tweeted twitter.com/StackMagento/status/728128332441640961
added 20 characters in body; edited tags
Source Link
7ochem
  • 7.6k
  • 16
  • 54
  • 82

app/etc/config.php:- 'modules' => array ( 'Ramesh_Sample' => 1, ),

'modules' => array ( 'Ramesh_Sample' => 1, ), 
 <?xml version="1.0"?>  <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">   <module name="Ramesh_Sample" schema_version="2.0.0">  </module> </config> 
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">  <router id="standard">   <route id="sample" frontName="sample">   <module name="Ramesh_Sample" />   </route>  </router> </config> 
<?php namespace Ramesh\Sample\Controller\Index; use Magento\Framework\App\Action\Context; //use \Magento\Framework\View\Result\PageFactory; class Index extends \Magento\Framework\App\Action\Action {  private $_resultPageFactory;  public function __construct(   Context $context,   \Magento\Framework\View\Result\PageFactory $resultPageFactory  )  {   parent::__construct($context);   $this->_resultPageFactory = $resultPageFactory;  }  public function execute()  {   $result = $this->_resultPageFactory->create();   return $result;  } } 
 <?php namespace Magento\Sample\Block; class Sample extends \Magento\Framework\View\Element\Template { } 
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">  <head>   <title>Hello World</title>  </head>   <body>   <referenceContainer name="content">   <block class="Sample\Ramesh\Block\Sample" name="sample" template="sample.phtml">   </block>   </referenceContainer>   </body>  </page> 

but iBut I got the following error:-

a:4:{i:0;s:380:"Recoverable Error: Argument 2 passed to Ramesh\Sample\Controller\Index\Index Ramesh\Sample\Controller\Index\Index::__construct() must be an instance instance of Magento\Framework\View\Result\PageFactory, none given, called called in /var/www/html/magento2/var var/generation/Ramesh/Sample/Controller/Index/Index/Interceptor.php on on line 14 and defined in /var/www/html/magento2/app app/code/Ramesh/Sample/Controller/Index/Index.php on on line 14";i:1;s:6109:"#0 /var/www/html/magento2/app app/code/Ramesh/Sample/Controller/Index/Index.php(14): Magento\Framework\App\ErrorHandler Magento\Framework\App\ErrorHandler->handler(4096, 'Argument 2 pass pass...', '/var/www/html/m...', 14, Array)

app/etc/config.php:- 'modules' => array ( 'Ramesh_Sample' => 1, ),

 <?xml version="1.0"?>  <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> <module name="Ramesh_Sample" schema_version="2.0.0"> </module> </config> 
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd"> <router id="standard"> <route id="sample" frontName="sample"> <module name="Ramesh_Sample" /> </route> </router> </config> 
<?php namespace Ramesh\Sample\Controller\Index; use Magento\Framework\App\Action\Context; //use \Magento\Framework\View\Result\PageFactory; class Index extends \Magento\Framework\App\Action\Action { private $_resultPageFactory; public function __construct( Context $context, \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { parent::__construct($context); $this->_resultPageFactory = $resultPageFactory; } public function execute() { $result = $this->_resultPageFactory->create(); return $result; } } 
 <?php namespace Magento\Sample\Block; class Sample extends \Magento\Framework\View\Element\Template { } 
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> <head> <title>Hello World</title> </head> <body> <referenceContainer name="content"> <block class="Sample\Ramesh\Block\Sample" name="sample" template="sample.phtml"> </block> </referenceContainer> </body>  </page> 

but i got the following error:-

a:4:{i:0;s:380:"Recoverable Error: Argument 2 passed to Ramesh\Sample\Controller\Index\Index::__construct() must be an instance of Magento\Framework\View\Result\PageFactory, none given, called in /var/www/html/magento2/var/generation/Ramesh/Sample/Controller/Index/Index/Interceptor.php on line 14 and defined in /var/www/html/magento2/app/code/Ramesh/Sample/Controller/Index/Index.php on line 14";i:1;s:6109:"#0 /var/www/html/magento2/app/code/Ramesh/Sample/Controller/Index/Index.php(14): Magento\Framework\App\ErrorHandler->handler(4096, 'Argument 2 pass...', '/var/www/html/m...', 14, Array)

app/etc/config.php:

'modules' => array ( 'Ramesh_Sample' => 1, ), 
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">   <module name="Ramesh_Sample" schema_version="2.0.0">  </module> </config> 
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">  <router id="standard">   <route id="sample" frontName="sample">   <module name="Ramesh_Sample" />   </route>  </router> </config> 
<?php namespace Ramesh\Sample\Controller\Index; use Magento\Framework\App\Action\Context; //use \Magento\Framework\View\Result\PageFactory; class Index extends \Magento\Framework\App\Action\Action {  private $_resultPageFactory;  public function __construct(   Context $context,   \Magento\Framework\View\Result\PageFactory $resultPageFactory  )  {   parent::__construct($context);   $this->_resultPageFactory = $resultPageFactory;  }  public function execute()  {   $result = $this->_resultPageFactory->create();   return $result;  } } 
namespace Magento\Sample\Block; class Sample extends \Magento\Framework\View\Element\Template { } 
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">  <head>   <title>Hello World</title>  </head>   <body>   <referenceContainer name="content">   <block class="Sample\Ramesh\Block\Sample" name="sample" template="sample.phtml">   </block>   </referenceContainer>   </body> </page> 

But I got the following error:

a:4:{i:0;s:380:"Recoverable Error: Argument 2 passed to Ramesh\Sample\Controller\Index\Index::__construct() must be an instance of Magento\Framework\View\Result\PageFactory, none given, called in var/generation/Ramesh/Sample/Controller/Index/Index/Interceptor.php on line 14 and defined in app/code/Ramesh/Sample/Controller/Index/Index.php on line 14";i:1;s:6109:"#0 app/code/Ramesh/Sample/Controller/Index/Index.php(14): Magento\Framework\App\ErrorHandler->handler(4096, 'Argument 2 pass...', '/var/www/html/m...', 14, Array)

added 32 characters in body
Source Link
Amit Bera
  • 77.8k
  • 21
  • 127
  • 240

a:4:{i:0;s:380:"Recoverable Error: Argument 2 passed to Ramesh\Sample\Controller\Index\Index::__construct() must be an instance of Magento\Framework\View\Result\PageFactory, none given, called in /var/www/html/magento2/var/generation/Ramesh/Sample/Controller/Index/Index/Interceptor.php on line 14 and defined in /var/www/html/magento2/app/code/Ramesh/Sample/Controller/Index/Index.php on line 14";i:1;s:6109:"#0 /var/www/html/magento2/app/code/Ramesh/Sample/Controller/Index/Index.php(14): Magento\Framework\App\ErrorHandler->handler(4096, 'Argument 2 pass...', '/var/www/html/m...', 14, Array)

a:4:{i:0;s:380:"Recoverable Error: Argument 2 passed to Ramesh\Sample\Controller\Index\Index::__construct() must be an instance of Magento\Framework\View\Result\PageFactory, none given, called in /var/www/html/magento2/var/generation/Ramesh/Sample/Controller/Index/Index/Interceptor.php on line 14 and defined in /var/www/html/magento2/app/code/Ramesh/Sample/Controller/Index/Index.php on line 14";i:1;s:6109:"#0 /var/www/html/magento2/app/code/Ramesh/Sample/Controller/Index/Index.php(14): Magento\Framework\App\ErrorHandler->handler(4096, 'Argument 2 pass...', '/var/www/html/m...', 14, Array)

a:4:{i:0;s:380:"Recoverable Error: Argument 2 passed to Ramesh\Sample\Controller\Index\Index::__construct() must be an instance of Magento\Framework\View\Result\PageFactory, none given, called in /var/www/html/magento2/var/generation/Ramesh/Sample/Controller/Index/Index/Interceptor.php on line 14 and defined in /var/www/html/magento2/app/code/Ramesh/Sample/Controller/Index/Index.php on line 14";i:1;s:6109:"#0 /var/www/html/magento2/app/code/Ramesh/Sample/Controller/Index/Index.php(14): Magento\Framework\App\ErrorHandler->handler(4096, 'Argument 2 pass...', '/var/www/html/m...', 14, Array)

a:4:{i:0;s:380:"Recoverable Error: Argument 2 passed to Ramesh\Sample\Controller\Index\Index::__construct() must be an instance of Magento\Framework\View\Result\PageFactory, none given, called in /var/www/html/magento2/var/generation/Ramesh/Sample/Controller/Index/Index/Interceptor.php on line 14 and defined in /var/www/html/magento2/app/code/Ramesh/Sample/Controller/Index/Index.php on line 14";i:1;s:6109:"#0 /var/www/html/magento2/app/code/Ramesh/Sample/Controller/Index/Index.php(14): Magento\Framework\App\ErrorHandler->handler(4096, 'Argument 2 pass...', '/var/www/html/m...', 14, Array)

Source Link
Ramesh
  • 91
  • 1
  • 1
  • 3

Creating custom module in magento2 show fatal error

I working on creating custom module in magento 2, but it's not working. Could you please suggest me where i went wrong?.

My module code:

app/etc/config.php:- 'modules' => array ( 'Ramesh_Sample' => 1, ),

app/code/Ramesh/Sample/etc/module.xml

 <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> <module name="Ramesh_Sample" schema_version="2.0.0"> </module> </config> 

app/code/Ramesh/Sample/etc/frontend/routes.xml

<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd"> <router id="standard"> <route id="sample" frontName="sample"> <module name="Ramesh_Sample" /> </route> </router> </config> 

app/code/Ramesh/Sample/Controller/Index/Index.php

<?php namespace Ramesh\Sample\Controller\Index; use Magento\Framework\App\Action\Context; //use \Magento\Framework\View\Result\PageFactory; class Index extends \Magento\Framework\App\Action\Action { private $_resultPageFactory; public function __construct( Context $context, \Magento\Framework\View\Result\PageFactory $resultPageFactory ) { parent::__construct($context); $this->_resultPageFactory = $resultPageFactory; } public function execute() { $result = $this->_resultPageFactory->create(); return $result; } } 

app/code/Ramesh/Sample/Block/Sample.php

 <?php namespace Magento\Sample\Block; class Sample extends \Magento\Framework\View\Element\Template { } 

app/code/Ramesh/Sample/views/frontend/layout/sample_index_index.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> <head> <title>Hello World</title> </head> <body> <referenceContainer name="content"> <block class="Sample\Ramesh\Block\Sample" name="sample" template="sample.phtml"> </block> </referenceContainer> </body> </page> 

app/code/Ramesh/Sample/view/frontend/templates/sample.phtml

<?php echo 'Hi I am Magento 2'; ?> 

but i got the following error:-

a:4:{i:0;s:380:"Recoverable Error: Argument 2 passed to Ramesh\Sample\Controller\Index\Index::__construct() must be an instance of Magento\Framework\View\Result\PageFactory, none given, called in /var/www/html/magento2/var/generation/Ramesh/Sample/Controller/Index/Index/Interceptor.php on line 14 and defined in /var/www/html/magento2/app/code/Ramesh/Sample/Controller/Index/Index.php on line 14";i:1;s:6109:"#0 /var/www/html/magento2/app/code/Ramesh/Sample/Controller/Index/Index.php(14): Magento\Framework\App\ErrorHandler->handler(4096, 'Argument 2 pass...', '/var/www/html/m...', 14, Array)