upgrade表结构UpgradeSchema.php
代码内容如下: <?php namespace Silk\Test\Setup; use Magento\Framework\Setup\UpgradeSchemaInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\SchemaSetupInterface; use Magento\Framework\DB\Ddl\Table; /** * @codeCoverageIgnore */ class UpgradeSchema implements UpgradeSchemaInterface { public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context) { $installer = $setup; $installer->startSetup(); if (version_compare($context->getVersion(), '1.0.1') < 0) { $installer->startSetup(); $tableName = $setup->getTable('silk_test'); if ($setup->getConnection()->isTableExists($tableName) == true) { $installer->getConnection() ->addColumn($installer->getTable('silk_test'),'e_profile_picture', array( 'type' => Table::TYPE_TEXT, 'nullable' => true, 'length' => 255, 'comment' => 'Profile Picture' )); } } $installer->endSetup(); } } 备注: 更新表结构要查看module.xml中的schema_version标签的值是否小于这里的版本号. 创建后台配置文件后台的配置文件是在etc/adminhtml/目录下创建,比如menu.xml,routes.xml,system.xml,di.xml等等,依次来解释下这些xml的作用 menu.xmlmenu.xml可以看作是配置当前模块在后台的导航位置的配置信息
代码内容如下: <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd"> <menu> <add id="Silk_Test::job_head" title="Test" module="Silk_Test" sortOrder="100" parent="Magento_Backend::stores" resource="Silk_Test::job_head" /> <add id="Silk_Test::job" title="Test" module="Silk_Test" sortOrder="20" parent="Silk_Test::job_head" action="test/job" resource="Silk_Test::job" /> </menu> </config> 说明:
acl.xml
代码内容如下: <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd"> <acl> <resources> <resource id="Magento_Backend::admin"> <!--<resource id="Magento_Backend::content">--> <resource id="Silk_Test::job_head" title="Test" sortOrder="100" > <resource id="Silk_Test::department" title="Departments" sortOrder="10"> <resource id="Silk_Test::department_save" title="Save Department" sortOrder="10" /> <resource id="Silk_Test::department_delete" title="Delete Department" sortOrder="20" /> </resource> <resource id="Silk_Test::job" title="Test" sortOrder="20"> <resource id="Silk_Test::job_save" title="Save Job" sortOrder="10" /> <resource id="Silk_Test::job_delete" title="Delete Job" sortOrder="20" /> </resource> </resource> <!--</resource>--> <!-- Admin config --> <resource id="Magento_Backend::stores"> <resource id="Magento_Backend::stores_settings"> <resource id="Magento_Config::config"> <resource id="Silk_Test::test" title="Test Section" /> </resource> </resource> </resource> </resource> </resources> </acl> </config> 查看权限位置:System > Permissions > User roles; routes.xmlroutes.xml是配置后台路由的信息
代码内容如下: <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd"> <router id="admin"> <route id="test" frontName="test"> <module name="Silk_Test" before="Magento_Backend" /> </route> </router> </config> 说明:
system.xmlsystem.xml是配置后台路由的信息
代码内容如下: <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> <system> <tab id="test" translate="label" sortOrder="1000"> <label>Test</label> </tab> <section id="test" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Test</label> <tab>test</tab> <resource>Silk_Test::test</resource> <group id="department" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Test configuration</label> <field id="view_list" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Show job list</label> <comment>Show list of the viewing </comment> <source_model>Magento\Config\Model\Config\Source\Yesno</source_model> </field> </group> </section> </system> </config>(责任编辑:好模板) |