Hello I am new to Magento & using Magento 2.1.7. I was learning to develop custom module. My module is working till the controller but it is not printing the data present in the template file named blockContent.phtml.
My Code:
App/Code/Funky/Hello/Controller/Path/HelloWorld.php
<?php
namespace Funky\Hello\Controller\Path;
use \Magento\Framework\App\Action\Action;
use \Magento\Framework\App\ResponseInterface;
use \Magento\Framework\View\Result\PageFactory;
use \Magento\Framework\App\Action\Context;
class HelloWorld extends Action
{
protected $pagefactory;
public function __construct(Context $context, PageFactory $pageFactory)
{
$this->pagefactory=$pageFactory;
Parent::__construct($context);
}
/**
* Dispatch request
*
* @return \Magento\Framework\Controller\ResultInterface|ResponseInterface
* @throws \Magento\Framework\Exception\NotFoundException
*/
public function execute()
{
echo "testing? is working";
return $this->pagefactory->create();
}
}
App/Code/Funky/Hello/Block/Main.php
<?php
namespace Funky\Hello\Block;
use \Magento\Framework\View\Element\Template;
class Main extends Template
{
public function _prepareLayout()
{
}
}
App/Code/Funky/Hello/etc/frontend/route.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation=
"urn:magento:framework:Module/etc/routes.xsd">
<router id="standard">
<route id="funky" frontName="funky">
<module name="Funky_Hello"/>
</route>
</router>
</config>
App/Code/Funky/Hello/etc/module.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation=
"urn:magento:framework:Module/etc/module.xsd">
<module name="Funky_Hello" setup_version="0.0.1"/>
</config>
App/Code/Funky/Hello/view/frontend/layout/funky_path_helloworld.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">
<body>
<referenceContainer name="columns.top">
<block class="Funky\Hello\Block\Main"
template="workin.phtml"
name="funky_hello_Hell"/>
</referenceContainer>
<referenceContainer name="content">
<block class="Funky\Hello\Block\Main"
template="Funky_Hello::blockContent.phtml"
name="funky_hello_HelloWorld"/>
</referenceContainer>
</body>
</page>
App/Code/Funky/Hello/view/frontend/layout/templates/blockContent.phtml
<b>Hello World!</b>
<h1>It is working or not???</h1>
<?php echo "nothing is happening why? ";?>
I have also created the registration.php.
If any one can tell me what exactly I am doing mistake?
Thank you in advance.
-
1Your blockContent.phtml file should be placed at app/code/Funky/Hello/view/frontend/templates/blockContent.phtmlQuan Le– Quan Le2017年07月24日 07:01:47 +00:00Commented Jul 24, 2017 at 7:01
1 Answer 1
Change the file path to
App/Code/Funky/Hello/view/frontend/templates/blockContent.phtml
instead of
App/Code/Funky/Hello/view/frontend/layout/templates/blockContent.phtml
In a layout folder there are always xml files.
-
1layout folder does not content template files2017年07月24日 14:32:09 +00:00Commented Jul 24, 2017 at 14:32