Magento2后台模块moudule其实很简单,可以参考已有的代码,规范写法,就可以开发出自己想要的功能模块,这里给一个基本的后台模块开发示范实例:
- To add a menu/sub-menu, check out the following files:
etc/adminhtml/menu.xmletc/adminhtml/routes.xml
- To bind a page to those submenus, check out the following files:
- You will notice the path to look like the action parameter from
etc/adminhtml/menu.xml Controller/Adminhtml/SampleOne/Index.phpController/Adminhtml/SampleTwo/Index.php
- You will notice the path to look like the action parameter from
- To add content to your freshly created pages, check out the following files:
view/adminhtml/layout/adminsample_sampleone_index.xmlview/adminhtml/templates/sample/one.phtml
- To add content to your freshly created pages and pass something to it, You can also check:
view/adminhtml/layout/adminsample_sampletwo_index.xmlController/Adminhtml/SampleTwo/Index.phpview/adminhtml/templates/sample/two.phtml
- To set and retrieve values from Magento2’s configuration you can check these files:
Controller/Adminhtml/SampleTwo/Index.phpetc/adminhtml/system.xmlConfiguration menu in Stores/Settings/Configuration is set hereetc/config.xmlDefault configurationview/adminhtml/templates/sample/two.phtml
- To see how ACLs are made, check these files:
etc/acl.xml- You’ll notice that most resource elements are from
etc/adminhtml/menu.xml
- To see how to have different layouts, check this file:
view/adminhtml/layout/adminsample_sampletwo_index.xml
- To see how we create a custom block and use it, check those files:
Block/Adminhtml/CustomBlock.phpview/adminhtml/layout/adminsample_sampletwo_index.xml
- To see how you use block functions, have a look at:
Block/Adminhtml/CustomBlock.phpview/adminhtml/templates/custom/one.phtml
- To call a helper from a block you can check:
Block/Adminhtml/CustomBlock.phpHelper/ConfigHelper.phpview/adminhtml/templates/custom/one.phtml
