2017-06-21 50 views
0

我正尝试在Magento 2中创建一个自定义窗体,并且无法将窗体的动作发送给正确的文件。Magento 2中的自定义窗体

到目前为止,我有以下的模块结构(我省略了一些文件模型和CRUD这可能没有必要在这里,如果需要的话,我会在结构上添加它们):

- Block - Adminhtml * Main.php - Controller - Adminhtml - MySection * Settings.php * Save.php - etc - adminhtml * menu.xml * routes.xml * acl.xml * module.xml - Setup * InstallSchema.php - view - adminhtml - layout * modulename_mysection_settings.xml * modulename_mysection_save.xml - templates * mysectionContent.phtml * content.phtml * registration

等\ adminhtml \ routes.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="modulename" frontName="modulename"> 
      <module name="modulename"/> 
     </route> 
    </router> 
</config> 

视图\ adminhtml \布局\ modulename_mysection_settings.xml内容:

<?xml version="1.0"?> 
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> 
    <head> 
     <title>My Title</title> 
    </head> 
    <body> 
     <referenceBlock name="content"> 
      <block template="mysectionContent.phtml" 
        class="Modulename\Block\Adminhtml\Main" 
        name="modulenameadminbackend_block_main"/> 
     </referenceBlock> 
    </body> 
</page> 

视图\ adminhtml \模板\ mysectionContent.phtml

<h1>My H1 Title</h1> 

<form class="form" action="save" method="post"> 

    <fieldset class="fieldset"> 
     <legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Test Form') ?></span></legend><br> 
     <div class="field required"> 
      <label for="number" class="label"> 
       <span><?php /* @escapeNotVerified */ echo __('Input') ?></span> 
      </label> 

      <div class="control"> 
       <input type="text" id="number" name="number" class="input-text"> 
       <input name="form_key" type="hidden" value="<?php /* @escapeNotVerified */ echo $block->getFormKey() ?>" /> 

      </div> 
     </div> 
    </fieldset> 

    <div class="actions-toolbar"> 
     <div class="primary"> 
      <button type="submit" class="action submit primary" title="<?php /* @escapeNotVerified */ echo __('Submit') ?>"> 
       <span><?php /* @escapeNotVerified */ echo __('Submit') ?></span> 
      </button> 
     </div> 
    </div> 

</form> 

有,我可以指导的形式,它的行动将是文件控制器/ Adminhtml/MySection/Save.php的方法吗?如果控制器文件不是要提交表单的正确位置,请告诉我应该在哪里以及如何执行此操作。之后,我需要从该文件中检索提交的变量变量。 我在Magento的新的和我似乎无法能够找到关于提交表单

+0

我应该将此问题移至[Magento Stack Exchange](https://magento.stackexchange.com)吗? –

回答

0

任何教程修改表格上的action属性这样

action="<?php echo $block->getUrl('modulename/mySection/save')?>" 

在一个侧面说明。您不应使用块和模板创建管理员表单。 使用ui-components。您可以将cms模块作为示例并执行相同的操作。