Magento 404在我的控制器的动作上

时间:2014-06-24 11:39:45

标签: php magento http-status-code-404

我正在创建一个带有网格的简单模块,其中包含一个添加按钮和表单。到目前为止,这是我的结构(基于我使用ModuleCreator脚本获得的经过试验和测试的结构):

/Integration/
--/controllers/
----ManualordersyncController.php
--/Block/
----Manualordersync.php
------/Adminhtml/
--------Manualordersync.php
----------/Manualordersync/
------------Grid.php
------------Edit.php
--------------/Edit/
----------------Form.php
----------------Tabs.php
------------------/Tab/
--------------------Form.php

在我的编辑器中看起来像这样:

enter image description here

正如您所看到的,我已经拥有了其他类似的网格,其中包含自己的编辑屏幕,标签,表单等......这些都可以正常工作。

但是,在这个新网格中,我正在处理 Manualordersync ,它正确显示网格:我使用phpMyAdmin手动添加了一些数据

enter image description here

但是,当我点击添加订单按钮时,我会得到一个404页面,我不确定它的来源。一直在看这几个小时。

有人可以帮忙吗?到目前为止,这是我的代码:


/Integration/
  /controllers/
    ManualordersyncController.php

class Companyname_Integration_Adminhtml_ManualordersyncController extends Mage_Adminhtml_Controller_action
{
    protected function _initAction()
    {
        // Init
        $this->loadLayout()
            ->_setActiveMenu('integration/manualordersync')
            ->_addBreadcrumb(Mage::helper('adminhtml')->__('Manual Order Sync'));
        return $this;
    }   

    public function indexAction()
    {
        // Render Page
        $this->_initAction()
             ->renderLayout();
    }

    public function editAction()
    {
        // Lad Data
        $id     = $this->getRequest()->getParam('id');
        $model  = Mage::getModel('ibi/manualordersync')->load($id);

        // Proceed If Data Is Loaded
        if ($model->getId() || $id == 0)
        {
            // Load Session
            $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
            if (!empty($data)) {
                $model->setData($data);
            }

            // Register Model
            Mage::register('manualordersync_data', $model);

            // Load Layout
            $this->loadLayout();
            $this->_setActiveMenu('integration/manualordersync');
            $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Manual Order Sync'));
            $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
            $this->_addContent($this->getLayout()->createBlock('integration/adminhtml_manualordersync_edit'))
                 ->_addLeft($this->getLayout()->createBlock('integration/adminhtml_manualordersync_edit_tabs'));

            // Render Page
            $this->renderLayout();
        }
        else
        {
            // Error
            Mage::getSingleton('adminhtml/session')->addError(Mage::helper('integration')->__('Order does not exist'));
            $this->_redirect('*/*/');
        }
    }

    public function saveAction()
    { /*snipped*/ }

    public function exportCsvAction()
    { /*snipped*/ }

    public function exportXmlAction()
    { /*snipped*/ }

    protected function _sendExportResponse($fileName, $content, $contentType = 'application/octet-stream')
    { /*snipped*/ }
}

/Integration/
  /Block/
    Manualordersync.php

class Companyname_Integration_Block_Manualordersync extends Mage_Core_Block_Template
{
    public function _prepareLayout()
    {
        return parent::_prepareLayout();
    }

     public function getManualordersync()     
     { 
        if (!$this->hasData('manualordersync')) {
            $this->setData('manualordersync', Mage::registry('manualordersync'));
        }
        return $this->getData('manualordersync');
    }
}

/Integration/
  /Block/
      /Adminhtml/
        Manualordersync.php

class Companyname_Integration_Block_Adminhtml_Manualordersync extends Mage_Adminhtml_Block_Widget_Grid_Container
{
    public function __construct() {
        $this->_controller = 'adminhtml_manualordersync';
        $this->_blockGroup = 'integration';
        $this->_headerText = Mage::helper('integration')->__('Manual Order Sync');
        $this->_addButtonLabel = Mage::helper('integration')->__('Add Order');
        parent::__construct();
    }
}

/Integration/
  /Block/
      /Adminhtml/
          /Manualordersync/
            Grid.php

class Companyname_Integration_Block_Adminhtml_Manualordersync_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct()
    {
        parent::__construct();
        $this->setId('manualordersyncGrid');
        $this->setDefaultSort('manualordersync_id');
        $this->setDefaultDir('ASC');
        $this->setSaveParametersInSession(true);
    }

    protected function _prepareCollection()
    {
        $collection = Mage::getModel('ibi/manualordersync')->getCollection();
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

    protected function _prepareColumns()
    {
        $this->addColumn('manualordersync_id', array(
            'header' => Mage::helper('integration')->__('ID'),
            'align' => 'left',
            'index' => 'manualordersync_id'
        ));

        $this->addColumn('order_number', array(
            'header' => Mage::helper('integration')->__('Order Number'),
            'align' => 'left',
            'index' => 'order_number'
        ));

        $this->addColumn('order_number', array(
            'header' => Mage::helper('integration')->__('Order Number'),
            'align' => 'left',
            'index' => 'order_number'
        ));

        $this->addColumn('created_at', array(
            'header' => Mage::helper('integration')->__('Created At'),
            'align' => 'left',
            'index' => 'created_at'
        ));

        $this->addColumn('created_by', array(
            'header' => Mage::helper('integration')->__('Created By'),
            'align' => 'left',
            'index' => 'created_by'
        ));

        $this->addColumn('action', array(
            'header' => Mage::helper('integration')->__('Action'),
            'width' => '100',
            'type' => 'action',
            'getter' => 'getId',
            'actions' => array(
                array(
                    'caption' => Mage::helper('integration')->__('Edit'),
                    'url' => array(
                        'base' => '*/*/edit'
                    ),
                    'field' => 'id'
                )
            ),
            'filter' => false,
            'sortable' => false,
            'index' => 'stores',
            'is_system' => true
        ));

        $this->addExportType('*/*/exportCsv', Mage::helper('integration')->__('CSV'));
        $this->addExportType('*/*/exportXml', Mage::helper('integration')->__('XML'));

        return parent::_prepareColumns();
    }

    public function getRowUrl($row)
    {
        return $this->getUrl('*/*/edit', array(
            'id' => $row->getId()
        ));
    }
}

/Integration/
  /Block/
      /Adminhtml/
          /Manualordersync/
            Edit.php

class Companyname_Integration_Block_Adminhtml_Manualordersync_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{
    public function __construct()
    {
        parent::__construct();

        $this->_objectId = 'id';
        $this->_blockGroup = 'integration';
        $this->_controller = 'adminhtml_manualordersync';

        $this->_updateButton('save', 'label', Mage::helper('integration')->__('Save'));
        $this->_updateButton('delete', 'label', Mage::helper('integration')->__('Delete'));

        $this->_addButton('saveandcontinue', array(
            'label'     => Mage::helper('adminhtml')->__('Save And Continue Edit'),
            'onclick'   => 'saveAndContinueEdit()',
            'class'     => 'save',
        ), -100);

        $this->_formScripts[] = "
            function saveAndContinueEdit(){
                editForm.submit($('edit_form').action+'back/edit/');
            }
        ";
    }

    public function getHeaderText()
    {
        if (Mage::registry('manualordersync_data') && Mage::registry('manualordersync_data')->getId()) {
            return Mage::helper('integration')->__("Edit Manual Sync for '%s'", $this->htmlEscape(Mage::registry('manualordersync_data')->getOrderNumber()));
        } else {
            return Mage::helper('integration')->__('Add Order');
        }
    }
}

/Integration/
  /Block/
      /Adminhtml/
          /Manualordersync/
              /Edit/
                Form.php

class Companyname_Integration_Block_Adminhtml_Manualordersync_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
    protected function _prepareForm()
    {
        $form = new Varien_Data_Form(array(
                                        'id' => 'edit_form',
                                        'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
                                        'method' => 'post'
                                     )
        );

        $form->setUseContainer(true);
        $this->setForm($form);
        return parent::_prepareForm();
    }
}

/Integration/
  /Block/
      /Adminhtml/
          /Manualordersync/
              /Edit/
                Tabs.php

class Companyname_Integration_Block_Adminhtml_Manualordersync_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
{
    public function __construct()
    {
        parent::__construct();
        $this->setId('integration_tabs');
        $this->setDestElementId('edit_form');
        $this->setTitle(Mage::helper('integration')->__('Order Information'));
    }

    protected function _beforeToHtml()
    {
        $this->addTab('form_section', array(
            'label'     => Mage::helper('integration')->__('Order Information'),
            'title'     => Mage::helper('integration')->__('Order Information'),
            'content'   => $this->getLayout()->createBlock('integration/adminhtml_manualordersync_edit_tab_form')->toHtml(),
        ));

        return parent::_beforeToHtml();
    }
}

/Integration/
  /Block/
      /Adminhtml/
          /Manualordersync/
              /Edit/
                  /Tab/
                    Form.php

class Companyname_Integration_Block_Adminhtml_Manualordersync_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
    protected function _prepareForm()
    {
        $form = new Varien_Data_Form();
        $this->setForm($form);

        $fieldset = $form->addFieldset('integration_form', array(
            'legend' => Mage::helper('integration')->__('Order Information')
        ));

        $resource = Mage::getSingleton('core/resource');
        $readConnection = $resource->getConnection('core_read');
        $tableName = $resource->getTableName('sales/order');
        $results = $readConnection->fetchAll("SELECT `increment_id` FROM $tableName");
        $order_numbers = array();
        foreach ($results as $order)
            $order_numbers[$order['increment_id']] = $order['increment_id'];
        $fieldset->addField('order_number', 'select', array(
            'label' => Mage::helper('integration')->__('Order Number'),
            'class' => 'required-entry',
            'required' => true,
            'name' => 'order_number',
            'values' => $order_numbers
        ));
        $resource = $readConnection = $tableName = $results = null;

        if (Mage::getSingleton('adminhtml/session')->getManualordersyncData()) {
            $form->setValues(Mage::getSingleton('adminhtml/session')->getManualordersyncData());
            Mage::getSingleton('adminhtml/session')->setManualordersyncData(null);
        } elseif (Mage::registry('manualordersync_data')) {
            $form->setValues(Mage::registry('manualordersync_data')->getData());
        }
        return parent::_prepareForm();
    }
}

1 个答案:

答案 0 :(得分:1)

看看@ Magento - Wiki - Custom Module with Custom Database Table

您需要一个可以转发的新动作

class <Namespace>_<Module>_Adminhtml_<Module>Controller extends Mage_Adminhtml_Controller_Action
{

    ....

    public function newAction()
    {
        $this->_forward('edit');
    }
相关问题