<?xml version='1.0'?>
<config>
<modules>
<MageCheck_Tutorial>
<active>true</active>
<codePool>local</codePool>
</MageCheck_Tutorial>
</modules>
</config>
File path: app/etc/modules/MageCheck_Tutorial.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='tutorial' frontName='tutorial'>
<module name='MageCheck_Tutorial' />
</route>
</router>
</config>
File path: app/code/MageCheck/Tutorial/etc/frontend/routes.xml
<?xml version='1.0'?>
<config>
<modules>
<MageCheck_Tutorial>
<version>0.1.0</version>
</MageCheck_Tutorial>
</modules>
<frontend>
<routers>
<tutorial>
<use>standard</use>
<args>
<module>MageCheck_Tutorial</module>
<frontName>tutorial</frontName>
</args>
</tutorial>
</routers>
</frontend>
</config>
File path: app/code/local/MageCheck/Tutorial/etc/config.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='MageCheck_Tutorial' setup_version='1.0.2'/>
</config>
File path: app/code/MageCheck/Tutorial/etc/frontend/module.xml
<?php
class MageCheck_Tutorial_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
echo 'Welcome to MageCheck Tutorials - Magento 1' . '<br><br>';
$this -> createControllerMethod();
}
public function createControllerMethod()
{
echo 'Your Frontend Controller is Working!';
}
}
File path: app/code/local/MageCheck/Tutorial/controllers/IndexController.php
<?php
namespace MageCheck\Tutorial\Controller\Index;
use \Magento\Framework\App\Action\Context;
class Index extends \Magento\Framework\App\Action\Action
{
/**
* @param Context $context
*/
public function __construct(
Context $context
){
parent::__construct($context);
}
public function execute()
{
// here are the functions you want to be displayed in controller;
}
public function function_name()
{
// here you put the code;
}
}
File path: app/code/MageCheck/Tutorial/Controller/Index/Index.php
Log in to Magento Admin panel, go to System -> Cache Management, Flush Magento Cache and that's it!
This function's instructions will be executed and magento will return the result to the user browser.
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'MageCheck_Tutorial',
__DIR__
);
The last thing you'll have to do is to Flush your cache.
File path: app/code/MageCheck/Tutorial/registration.php
Open your favourite browser and give your site this route:
http://example.com/tutorial/index/index
And now, this path will call your controller function and display the result.
This is the sample way to create a Frontend Controller in Magento!
Have you decided on an online Business Plan website?