0

I am new at developing Magento 2 (Magento 2.3), I develop module to show my custom template But I get this error

when I die('sumthing') in execute function it works correctly

1 exception(s): Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Parcode\Contacts\Controller\Index\index\Interceptor

this my code

route.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="contacts" frontName="contacts">
            <module name="Parcode_Contacts" />
        </route>
    </router>
</config>

my Controller: Index

<?php
namespace Parcode\Contacts\Controller\Index;


class Index extends \Magento\Framework\App\Action\Action
{
    protected $_pageFactory;
    protected $_postFactory;
    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $pageFactory
    )
    {
        $this->_pageFactory = $pageFactory;
        return parent::__construct($context);
    }
    public function execute()
    {

        // die('somthing'); works correctly
        return $this->_pageFactory->create();
    }
}

layout file:

view/layout/contacts_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceBlock name="content">
            <block class="Parcode\Contacts\Block\Contact" name="contacts_index_index" template="Parcode_Contacts::index_index.phtml"  />
        </referenceBlock>
</page>

template: view/templates/index_index.phtml

5
  • Would you include the other two files you referenced? Also, do you have a plugin somewhere? As a side note the template should be in your module's view/frontend/templates/ and the layout: view/frontend/layout/. Jan 8 '19 at 23:09
  • can you share you layout coding?
    – Sourav
    Jan 8 '19 at 23:56
  • @sourav yes of course
    – majid
    Jan 9 '19 at 0:11
  • check my answer
    – Sourav
    Jan 9 '19 at 0:20
  • if solve your problem please tick
    – Sourav
    Jan 9 '19 at 0:21
0

I have checked you are using wrong template path. Always use templates not template.

In magento 2 module templates are store in Path: view/frontend/templates/

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.