How to Create Route and Controller in Magento 2
To show "Hi World" on your own page in Magento 2, follow these means:
1. Register a switch for the retail facade.
Make this record:
application/code/<VendorName>/<ModuleName>/and so forth/frontend/routes.xml
what's more, add the accompanying code there:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-case" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/and so forth/routes.xsd">
<switch id="standard">
<course id="VendorName_ModuleName" frontName="path">
<module name="VendorName_ModuleName"/>
</route>
</router>
</config>
You can utilize the engineer name (VendorName) related with the module name (ModuleName) as the switch id. The frontName is utilized in the URL to get to your regulators.
The two names must be one of a kind.
2. Make a regulator.
Add the new document:
application/code/<VendorName>/<ModuleName>/Controller/Index/Index.php
add the accompanying code in it:
<?php
namespace VendorName\ModuleName\Controller\Index;
class Index expands \Magento\Framework\App\Action\Action
{
public capability execute()
{
reverberation 'Hi World';
exit();
}
}
All regulators need to contain a public execute strategy. It is called while getting to the regulator.
The retail facade regulators are acquired from the \Magento\Framework\App\Action\Action class.
Focus!
As per the Magento 2 code necessities guidelines, the utilization of the reverberation constructor in PHP documents is denied, and the utilization of the leave constructor is completely restricted. You might utilize them just briefly for testing.
In the models, we will make a Faq module for Frequently Asked Question (FAQ).
The subsequent module design will seem to be this:
├── application
│ └── code
│ └── // назва розробника - VendorName
│ └── Faq//назва модуля - ModuleName
│ ├── and so on
│ │ ├──module.xml
│ │ └──frontend
│ │ └── routes.xm
│ │
│ ├── registration.php
│ └── Regulator
│ └── List
│ └── Index.php
│
The Faq module documents can be seen on GitHub.
3. Clear Magento Cache. Run this CLI order:
php container/magento cache:clean
4. Run DI (Dependency Injections). Run the CLI order:
php container/magento setup:di:compile
5. Visit the new page.
To see the recently made page, follow the connection:
http://your-magento-store.com/way/list/record/
You will see the text:
Hi World
References:
https://viesearch.com/1sluf/submission-success
https://meetanshi-blog.quora.com/How-to-Create-Route-and-Controller-in-Magento-2
https://in.pinterest.com/pin/833377106060043947
https://ello.co/meetanshi/post/tyya9lf8qol4uekhzmjloa
https://www.patreon.com/posts/how-to-create-in-68498569
https://steemit.com/magento/@meetanshi/how-to-create-route-and-controller-in-magento-2
https://ko-fi.com/post/How-to-Create-Route-and-Controller-in-Magento-2-E1E0DK2OK
http://www.video-bookmark.com/bookmark/5329454/how-to-create-route-and-controller-in-magento-2/
https://www.diigo.com/annotated/550dc9cce78039d91ae8510c1d5c7c9d
https://www.kaskus.co.id/post/62be760e95de8e334f636973/1
https://adfty.biz/technology/how-to-create-route-and-controller-in-magento-2/
https://www.uplabs.com/posts/how-to-create-route-and-controller-in-magento-2
https://meetanshi.wordpress.com/2022/07/01/how-to-create-route-and-controller-in-magento-2/
https://meetanshi.blogspot.com/2022/06/how-to-create-route-and-controller-in.html
https://dribbble.com/shots/18628390-How-to-Create-Route-and-Controller-in-Magento-2
https://www.ebaumsworld.com/blogs/how-to-create-route-and-controller-in-magento-2/87204659/
https://vin.gl/p/4562955?wsrc=link
https://storeboard.com/blogs/technology/how-to-create-route-and-controller-in-magento-2/5500962
https://www.symbaloo.com/shared/AAAABIrDhT8AA41_lbFzBQ==
https://www.anibookmark.com/site/how-to-create-route-and-controller-in-magento-2-ab800763.html
https://cart-help.com/topic/9498-how-to-create-route-and-controller-in-magento-2/
https://www.bloglovin.com/@meetanshi52/how-to-create-route-controller-in-magento
Comments
Post a Comment