here step how to working with controller, i will create 2 controllers file, my objective is, to run following url
http://127.0.0.1/magento21/index.php/hellomagentoworld/index/index and
http://127.0.0.1/magento21/index.php/hellomagentoworld/index/test
- create file app\code\Ansyori\HelloWorld\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="hellomagentoworld" frontName="hellomagentoworld"> <module name="Ansyori_HelloWorld" /> </route> </router> </config>
- next, create file app\code\Ansyori\HelloWorld\Controller\Index\Index.php
-
<?php namespace Ansyori\HelloWorld\Controller\Index; class Index extends \Magento\Framework\App\Action\Action { public function execute() { echo 'Hello World!'; } }
- and app\code\Ansyori\HelloWorld\Controller\Index\Test.php
-
<?php namespace Ansyori\HelloWorld\Controller\Index; class Test extends \Magento\Framework\App\Action\Action { public function execute() { echo 'Test Horray!'; } }
- dont forget, clear magento cache!
- then try open both URLs on your browser :
- http://127.0.0.1/magento21/index.php/hellomagentoworld/index/index
http://127.0.0.1/magento21/index.php/hellomagentoworld/index/test
Comments are closed.