0

关闭我可以做到我混合2个答案中的代码来制作我的页面

我想用我的自定义数据库表制作特殊订单页面

我可以像这样创建新的 magento admin 页面布局吗

我想要这样的页面布局

我想展示

订单 OrdersDate CustomerID CustomerCompany SKU ProductName Qty, Total Status Action

并且 mydatabase 表名在表中的字段中有特殊顺序

order_no PK (from product id)
order_item_number PK (to show in Orders)
creat_date (to show in OrdersDate)
Cusid (to show in CustomerID)
Cusname (to show in CustomerCompany)
sku (to show in SKU)
Productname (to show in ProductName )
price 
qty (to show in Qty,)
total_price (to show in Total)
status (to show in Status)

像这样的表中的数据(order_no + order_item_no = pk)

1 1 日期 cusid cusname sku P.name 价格 数量 总状态

2 1 日期 cusid cusname sku P.name 价格 数量 总状态

2 2 日期 cusid cusname sku P.name 价格 数量 总状态

如何使用此表在我的自定义管理页面中显示

4

2 回答 2

4

按照以下步骤在管理面板中使用您的自定义表创建模块。

在本地目录 (app/code/local/Pfay/Test) 中创建模块,其中 test -> 。在这个结构中创建所有这些目录 Helper,etc,Block,Model,Controllers

让我们从 etc 创建 config.xml 文件开始:

<?xml version="1.0"?>
  <config>
    <modules>
        <Pfay_Test>
          <version>1.0.0</version>
        </Pfay_Test>
    </modules>
    <global>
            <blocks>
                <test>
                     <class>Pfay_Test_Block</class>
                </test>
            </blocks>
            <models>
                <test>
                     <class>Pfay_Test_Model</class>
                     <resourceModel>test_mysql4</resourceModel>
                 </test>
                <test_mysql4>
                     <class>Pfay_Test_Model_Mysql4</class>
                     <entities>
                         <test>
                           <table>pfay_test</table>
                         </test>
                      </entities>
                </test_mysql4>
            </models>
                <!-- allow the plugin to read and write -->
            <resources>
                    <!-- connection to write -->
                    <test_write>
                        <connection>
                            <use>core_write</use>
                        </connection>
                    </test_write>
                    <!-- connection to read -->
                   <test_read>
                      <connection>
                         <use>core_read</use>
                      </connection>
                   </test_read>
            </resources>
             <!-- -/- -->
    </global>
     <frontend>
       <routers>
          <routeurfrontend>
              <use>standard</use>
              <args>
                 <module>Pfay_Test</module>
                 <frontName>test</frontName>
              </args>
          </routeurfrontend>
       </routers>
       <layout>
           <updates>
                <test>
                     <file>test.xml</file>
                </test>
            </updates>
        </layout>
    </frontend>
        <admin>
         <routers>
             <test>
                <use>admin</use>
                <args>
                   <module>Pfay_Test</module>
                   <frontName>admintest</frontName>
                </args>
             </test>
          </routers>
     </admin>
     <adminhtml>
       <layout>
          <updates>
              <test>
                  <file>test.xml</file>
               </test>
          </updates>
       </layout>
       <menu>
          <test translate="title" module="adminhtml">
             <title>Import XLS</title>
             <sort_order>100</sort_order>
             <children>
                 <set_time>
                       <title>Add product through XLS</title>
                       <action>admintest/adminhtml_index</action>
                  </set_time>
              </children>
           </test>
        </menu>
    </adminhtml>
</config>

我的表名是Pfay_test添加你的表名而不是这个。

现在在控制器中创建目录Adminhtml在此创建中创建您的控制器IndexController.php

<?php
class Pfay_Test_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
    protected function _initAction()
    {
        $this->loadLayout()->_setActiveMenu('test/set_time')
                ->_addBreadcrumb('test Manager','test Manager');
       return $this;
     }
      public function indexAction()
      {
         $this->_initAction();
         $this->renderLayout();
      }

}

其中set_time是您在 config.xml 文件中添加的菜单名称。

现在移动到您将创建网格的块部分。在 Block 目录中创建Adminhtml > Grid.php

class Pfay_Test_Block_Adminhtml_Grid extends Mage_Adminhtml_Block_Widget_Grid_Container
{
    public function __construct()
    {
     //where is the controller
     $this->_controller = 'adminhtml_test';
     $this->_blockGroup = 'test';
     //text in the admin header
     $this->_headerText = 'XLS file management';
     //value of the add button

     parent::__construct();
     }
}

接下来创建一个目录 Test > Grid.php

<?php
class Pfay_Test_Block_Adminhtml_Test_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
   public function __construct()
   {
       parent::__construct();
       $this->setId('contactGrid');
       $this->setDefaultSort('id_pfay_test');
       $this->setDefaultDir('DESC');
       $this->setSaveParametersInSession(true);
   }
   protected function _prepareCollection()
   {
      $collection = Mage::getModel('test/test')->getCollection();
      $this->setCollection($collection);
      return parent::_prepareCollection();
    }
   protected function _prepareColumns()
   {
       $this->addColumn('id_pfay_test',
             array(
                    'header' => 'ID',
                    'align' =>'right',
                    'width' => '50px',
                    'index' => 'id_pfay_test',
               ));
       $this->addColumn('nom',
               array(
                    'header' => 'nom',
                    'align' =>'left',
                    'index' => 'nom',
              ));
       $this->addColumn('prenom', array(
                    'header' => 'prenom',
                    'align' =>'left',
                    'index' => 'prenom',
             ));
        $this->addColumn('telephone', array(
                     'header' => 'telephone',
                     'align' =>'left',
                     'index' => 'telephone',
          ));
         return parent::_prepareColumns();
    }
    public function getRowUrl($row)
    {
         return $this->getUrl('*/*/edit', array('id' => $row->getId()));
    }
}

现在转到您的模型内部模型创建Test.phpMysql4

在 Test.php 中:

<?php
class Pfay_Test_Model_Test extends Mage_Core_Model_Abstract
{
     public function _construct()
     {
         parent::_construct();
         $this->_init('test/test');
     }
}

这里(测试/测试)是 Pfay_<modulename>_Model_<modulename> -> (<modulename>/<modulename>)

现在在Pfay > Test > Model > Mysql4文件夹中创建 Test.php 和 Test

在 Test.php 中:

<?php
class Pfay_Test_Model_Mysql4_Test extends Mage_Core_Model_Mysql4_Abstract
{
     public function _construct()
     {
         $this->_init('test/test', 'id_pfay_test');
     }
}

其中id_pfay_test是表的唯一键。

Pfay >Test >Model >Mysql4 >Test > create a file Collection.php

<?php
class Pfay_Test_Model_Mysql4_Test_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
 {
     public function _construct()
     {
         parent::_construct();
         $this->_init('test/test');
     }
}

最后一步通知magento您的模块:在中创建文件Pfay_Test.xml

/app/etc/模块

<?xml version="1.0"?>
<config>
    <modules>
        <Pfay_Test>
            <active>true</active>
            <codePool>local</codePool>
        </Pfay_Test>
   </modules>

</config>

注意:根据您更改模块名称和包名称。

如果您对此有任何疑问,请随时咨询。

于 2014-12-03T05:13:48.687 回答
0

尝试使用内置的 Magento Grid。至于不重复的内容,试试这个:

于 2014-12-03T03:46:47.400 回答