我有一个网格可以加载我的项目,并且它正常工作但是当我点击该项目时它应该重定向到我的编辑页面,但不知怎的,它给我的404找不到。我错过了什么吗?
这是 config.xml :
<config>
<modules>
<Mjsi_Walmartapi>
<version>0.0.1</version>
</Mjsi_Walmartapi>
</modules>
<global>
<models>
<Walmartapi>
<class>Mjsi_Walmartapi_Model</class>
<resourceModel>Walmartapi_resource</resourceModel>
</Walmartapi>
<Walmartapi_resource>
<class>Mjsi_Walmartapi_Model_Resource</class>
<entities>
<item>
<table>Walmartapi_item</table>
</item>
<order>
<table>Walmartapi_order</table>
</order>
</entities>
</Walmartapi_resource>
</models>
<resources>
<walmart_setup>
<setup>
<module>Mjsi_Walmartapi</module>
<class>Mage_Core_Model_Resource_Setup</class>
</setup>
</walmart_setup>
</resources>
<blocks>
<Walmartapi>
<class>Mjsi_Walmartapi_Block</class>
</Walmartapi>
</blocks>
<helpers>
<Walmartapi>
<class>Mjsi_Walmartapi_Helper</class>
</Walmartapi>
</helpers>
<events>
<controller_action_predispatch>
<observers>
<Walmartapi_observer>
<class>Walmartapi/observer</class>
<method>controllerActionPredispatch</method>
</Walmartapi_observer>
</observers>
</controller_action_predispatch>
</events>
</global>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<Walmartapi before="Mage_Adminhtml">Mjsi_Walmartapi_Adminhtml</Walmartapi>
</modules>
</args>
</adminhtml>
</routers>
</admin>
这是我的 adminhtml.xml :
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<system>
<children>
<config>
<children>
<walmart>
<title>Walmartapi</title>
</walmart>
</children>
</config>
</children>
</system>
<Walmartapi translate="title" module="Walmartapi">
<title>Walmartapi</title>
<children>
<item translate="title" module="Walmartapi">
<title>Product</title>
<sort_order>0</sort_order>
</item>
<order translate="title" module="Walmartapi">
<title>Order</title>
<sort_order>10</sort_order>
</order>
<choose translate="title" module="Walmartapi">
<title>Choose</title>
<sort_order>15</sort_order>
</choose>
</children>
</Walmartapi>
</children>
</admin>
</resources>
</acl>
<menu>
<Walmartapi translate="title" module="Walmartapi">
<title>Walmart</title>
<sort_order>1000</sort_order>
<children>
<item translate="title" module="Walmartapi">
<title>Manage Items</title>
<action>adminhtml/walmartapi_item</action>
<sort_order>0</sort_order>
</item>
<order translate="title" module="Walmartapi">
<title>Orders</title>
<action>adminhtml/walmartapi_order</action>
<sort_order>10</sort_order>
</order>
<choose translate="title" module="Walmartapi">
<title>Choose Item</title>
<action>adminhtml/walmartapi_choose</action>
<sort_order>15</sort_order>
</choose>
</children>
</Walmartapi>
</menu>
这是 ChooseController.php :
class Mjsi_Walmartapi_Adminhtml_Walmartapi_ChooseController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout();
$this->_addContent($this->getLayout()->createBlock('Walmartapi/adminhtml_choose'));
return $this->renderLayout();
}
}
这是 Grid.php :
<?php
class Mjsi_Walmartapi_Block_Adminhtml_Choose_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function getRowUrl($item)
{
return $this->getUrl('*/walmartapi_choose/edit', array('item_id' => $item->getId()));
}
protected function _getStore()
{
$storeId = (int) $this->getRequest()->getParam('store', 0);
return Mage::app()->getStore($storeId);
}
protected function _prepareCollection()
{
$walmartProduct = Mage::getModel("Walmartapi/item")->getCollection();
$walmartProduct->getSelect()
->reset(Zend_Db_Select::COLUMNS)
->columns(array('sku',));
foreach ($walmartProduct as $item) {
$walmartItem[] = $item->getData();
}
$store = $this->_getStore();
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('sku')
->addAttributeToSelect('name')
->addAttributeToSelect('attribute_set_id')
->addAttributeToSelect('type_id');
if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
$collection->joinField(
'qty',
'cataloginventory/stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left'
);
}
if ($store->getId()) {
//$collection->setStoreId($store->getId());
$adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;
$collection->addStoreFilter($store);
$collection->joinAttribute(
'name',
'catalog_product/name',
'entity_id',
null,
'inner',
$adminStore
);
$collection->joinAttribute(
'price',
'catalog_product/price',
'entity_id',
null,
'left',
$store->getId()
);
} else {
$collection->addAttributeToSelect('price');
}
$this->setCollection($collection);
for ($i=0; $i < count($walmartItem); $i++) {
$collection->addAttributeToFilter('sku', array('nlike' => $walmartItem[$i]));
}
parent::_prepareCollection();
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn(
'name',
array(
'header'=> Mage::helper('catalog')->__('Name'),
'index' => 'name',
)
);
$store = $this->_getStore();
if ($store->getId()) {
$this->addColumn(
'custom_name',
array(
'header'=> Mage::helper('catalog')->__('Name in %s', $this->escapeHtml($store->getName())),
'index' => 'custom_name',
)
);
}
$this->addColumn(
'sku',
array(
'header'=> Mage::helper('catalog')->__('SKU'),
'width' => '80px',
'index' => 'sku',
)
);
$store = $this->_getStore();
$this->addColumn(
'price',
array(
'header'=> Mage::helper('catalog')->__('Price'),
'type' => 'price',
'currency_code' => $store->getBaseCurrency()->getCode(),
'index' => 'price',
)
);
if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
$this->addColumn(
'qty',
array(
'header'=> Mage::helper('catalog')->__('Qty'),
'width' => '100px',
'type' => 'number',
'index' => 'qty',
)
);
}
;
if (Mage::helper('catalog')->isModuleEnabled('Mage_Rss')) {
$this->addRssList('rss/catalog/notifystock', Mage::helper('catalog')->__('Notify Low Stock RSS'));
}
return $this;
}
}
这是 Edit.php :
<?php
class Mjsi_Walmartapi_Block_Adminhtml_Choose_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{
public function __construct()
{
$this->_objectId = 'item_id';
$this->_blockGroup = 'Walmartapi';
$this->_controller = 'adminhtml_choose';
parent::__construct();
}
public function getHeaderText()
{
return Mage::helper('Walmartapi')->__('Edits Item');
}
public function getSaveUrl()
{
return $this->getUrl('*/walmartapi_choose/save', array('_current' => true));
}
}
这是 Form.php :
<?php
class Mjsi_Walmartapi_Block_Adminhtml_Choose_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _initFormValues()
{
if ($item = Mage::registry('current_item')) {
$data = $item->getData();
$this->getForm()->setValues($data);
}
if ($data = Mage::getSingleton('adminhtml/session')->getData('item_form_data', true)) {
$this->getForm()->setValues($data);
}
}
protected function _prepareForm()
{
$form = new Varien_Data_Form(
array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post')
);
$fieldset = $form->addFieldset('base_fieldset', array('legend' => Mage::helper('Walmartapi')->__('Add New Item')));
$fieldset->addField('mart', 'text', array(
'name' => 'mart',
'label' => Mage::helper('Walmartapi')->__('Mart'),
'title' => Mage::helper('Walmartapi')->__('Mart'),
'required' => true
));
$fieldset->addField('sku', 'text', array(
'name' => 'sku',
'label' => Mage::helper('Walmartapi')->__('SKU'),
'title' => Mage::helper('Walmartapi')->__('SKU'),
'required' => true
));
$fieldset->addField('wpid', 'text', array(
'name' => 'wpid',
'label' => Mage::helper('Walmartapi')->__('Walmart Product ID'),
'title' => Mage::helper('Walmartapi')->__('Walmart Product ID'),
'required' => true
));
$fieldset->addField('upc', 'text', array(
'name' => 'upc',
'label' => Mage::helper('Walmartapi')->__('UPC'),
'title' => Mage::helper('Walmartapi')->__('UPC'),
'required' => true
));
$fieldset->addField('gtin', 'text', array(
'name' => 'gtin',
'label' => Mage::helper('Walmartapi')->__('GTIN'),
'title' => Mage::helper('Walmartapi')->__('GTIN'),
'required' => true
));
$fieldset->addField('product_name', 'text', array(
'name' => 'product_name',
'label' => Mage::helper('Walmartapi')->__('Product Name'),
'title' => Mage::helper('Walmartapi')->__('Product Name'),
'required' => true
));
$fieldset->addField('product_type', 'text', array(
'name' => 'product_type',
'label' => Mage::helper('Walmartapi')->__('Product Type'),
'title' => Mage::helper('Walmartapi')->__('Product Type'),
'required' => true
));
$fieldset->addField('currency', 'text', array(
'name' => 'currency',
'label' => Mage::helper('Walmartapi')->__('Currency'),
'title' => Mage::helper('Walmartapi')->__('Currency'),
'required' => true
));
$fieldset->addField('amount', 'text', array(
'name' => 'amount',
'label' => Mage::helper('Walmartapi')->__('Amount'),
'title' => Mage::helper('Walmartapi')->__('Amount'),
'required' => true
));
$fieldset->addField('quantity', 'text', array(
'name' => 'quantity',
'label' => Mage::helper('Walmartapi')->__('Quantity'),
'title' => Mage::helper('Walmartapi')->__('Quantity'),
'required' => true
));
$fieldset->addField('published_status', 'text', array(
'name' => 'published_status',
'label' => Mage::helper('Walmartapi')->__('Publish Status'),
'title' => Mage::helper('Walmartapi')->__('Publish Status'),
'required' => true
));
$form->setUseContainer(true);
$this->setForm($form);
}
}
这里有截图: enter image description here