2012-06-11 93 views
1

我試圖寫一個adminhtml模塊變得非常困惑!Magento管理網格問題

有效我有書面的IndexController和工作,我試圖調用一個網格塊:我使用的是控制器通過調用該方法

$<?php 

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

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

protected function _prepareColumns() 
{ 
    $this->addColumn('category_name', array(
     'header' => Mage::helper('OutOfStock')->__('Category'), 
     'align'  =>'right', 
     'width'  => '50px', 
     'index'  => 'web_id', 
)); 

    $this->addColumn('sku', array(
     'header' => Mage::helper('OutOfStock')->__('SKU'), 
     'align'  =>'left', 
     'index'  => 'title', 
)); 

/* 
    $this->addColumn('quantity', array(
'header' => Mage::helper('OutOfStock')->__('Quantity Available'), 
'width'  => '150px', 
'index'  => 'content', 
)); 
*/ 

    $this->addColumn('Backorder allowed', array(
     'header' => Mage::helper('OutOfStock')->__('Status'), 
     'align'  => 'left', 
     'width'  => '80px', 
     'index'  => 'status', 
     'type'  => 'options', 
     'options' => array(
      1 => 'Enabled', 
      2 => 'Disabled', 
    ), 
)); 

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

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

    return parent::_prepareColumns(); 
} 


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

<?php 
class MyTuxedo_OutOfStock_IndexController extends Mage_Adminhtml_Controller_Action 
{ 
public function indexAction() 
{ 
    $this->loadLayout(); 
    $this->_addContent($this->getLayout()->createBlock('OutOfStock/adminhtml_OutOfStock')); 
    $this->renderLayout(); 
    } 
} 

佈局文件包括以下內容:

<?xml version=「1.0??> 
<layout version=「0.1.0?> 
    <OutOfStock_index_index> 
    <reference name=「content」> 
    <block type=「OutOfStock/adminhtml_OutOfStock「 name=「OutOfStock「 /> 
</reference> 
</OutOfStock_index_index> 
</layout> 

最後塊基文件:

<?php 
class MyTuxedo_OutOfStock_Block_Adminhtml_OutOfStock extends Mage_Adminhtml_Block_Widget_Grid_Container 
{ 
public function __construct() 
{ 
$this->_controller = ‘adminhtml_OutOfStock’; 
$this->_blockGroup = ‘OutOfStock’; 
$this->_headerText = Mage::helper(‘OutOfStock’)->__(‘Item Manager’); 
    $this->_addButtonLabel = Mage::helper(‘OutOfStock’)->__(‘Add Item’); 
parent::__construct(); 
    } 
} 

我已經嘗試了一切,並獲得網格顯示在後端,它只是絕對拒絕工作。在indexcontroller中運行echo工作正常,我甚至在控制器內調用了CMS靜態塊,只是調用塊本身拒絕工作。

有沒有人有任何建議?如果需要,也可以發佈config.xml,只是不想讓問題膨脹太多!

謝謝!

的Config.xml

<?xml version="1.0"?> 
<config> 
<modules> 
    <MyTuxedo_OutOfStock>  
    <version>0.1.0</version> 
    </MyTuxedo_OutOfStock> 
</modules> 
<adminhtml> 
    <layout>  
    <updates>  
     <outofstock>   
     <file>OutOfStock.xml</file>  
     </outofstock>  
    </updates> 
</layout>   
<acl>   
<resources>  
     <admin>  
     <children>  
       <outofstock>  
        <title>Out of Stock Items</title>  
        <children>       
      <OutOfStock>  
        <title>Out of Stock Items</title>      
      </OutOfStock>     
     </children>   
      </outofstock>    
    </children>  
     </admin> 
     </resources> 
    </acl> 
    </adminhtml> 
    <global> 
    <models> 
<outofstock> 
    <class>MyTuxedo_OutOfStock_Model</class> 
</outofstock> 
    </models>  
    <helpers>  
    <outofstock> 
     <class>MyTuxedo_OutOfStock_Helper</class>  
    </outofstock> 
    </helpers> 
<blocks> 
<outofstock> 
<class>MyTuxedo_OutOfStock_Block</class> 
</outofstock> 
</blocks> 
</global> 
    <admin> 
    <routers> 
     <MyTuxedo_OutOfStock> 
      <use>admin</use> 
      <args> 
       <module>MyTuxedo_OutOfStock</module> 
       <frontName>OutOfStock</frontName> 
      </args> 
     </MyTuxedo_OutOfStock> 
    </routers> 
</admin> 
</config> 

我已經修改了配置範圍,但我仍然獲得:

2012-06-12T09:43:35+00:00 ERR (3): 
exception 'Mage_Core_Exception' with message 'Invalid block type:  MyTuxedo_OutOfStock_Block_Adminhtml_Nostock' in /chroot/home/mytuxedo /developer.mytuxedo.co.uk/html/app/Mage.php:550 
Stack trace: 
#0 /chroot/home/mytuxedo/developer.mytuxedo.co.uk/html/includes/src/__default.php(24835): Mage::throwException('Invalid block t...') 
#1 /chroot/home/mytuxedo/developer.mytuxedo.co.uk/html/includes/src/__default.php(24777): Mage_Core_Model_Layout->_getBlockInstance('OutOfStock/Admi...', Array) 
#2 /chroot/home/mytuxedo/developer.mytuxedo.co.uk/html/app/code/local/MyTuxedo/OutOfStock/controllers/Adminhtml/OutOfStockController.php(7): Mage_Core_Model_Layout->createBlock('OutOfStock/Admi...') 
#3 /chroot/home/mytuxedo/developer.mytuxedo.co.uk/html/includes/src/__default.php(12068): MyTuxedo_OutOfStock_Adminhtml_OutOfStockController->indexAction() 
#4 /chroot/home/mytuxedo/developer.mytuxedo.co.uk/html/includes/src/__default.php(16116): Mage_Core_Controller_Varien_Action->dispatch('index') 
#5 /chroot/home/mytuxedo/developer.mytuxedo.co.uk/html/includes/src/__default.php(15713): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http)) 
#6 /chroot/home/mytuxedo/developer.mytuxedo.co.uk/html/includes/src/__default.php(17973): Mage_Core_Controller_Varien_Front->dispatch() 
#7 /chroot/home/mytuxedo/developer.mytuxedo.co.uk/html/app/Mage.php(596): Mage_Core_Model_App->run(Array) 
#8 /chroot/home/mytuxedo/developer.mytuxedo.co.uk/html/index.php(97): Mage::run('', 'store') 
#9 {main} 
+0

在您的索引中,執行var_dump($ this-> getLayout() - > createBlock('OutOfStock/adminhtml_OutOfStock'));看看這是否給你塊對象。我想知道你的班級名稱或查詢是否可能稍微偏離。 –

+0

你可以發佈你的config.xml,只是爲了檢查塊別名。也可以嘗試不同的外殼,因爲Magento在查找名稱時會做一些大小寫轉換。 –

+0

我認爲外殼是問題,在confix.xml中你有outofstock,但在你的lookup中使用OutOfStock,嘗試outofstock/adminhtml_OutOfStock在你的佈局/索引控制器 –

回答

0

想通了,沒有注意到在編譯過程中切換(不知道爲什麼我打開了它?!)。 - 浪費時間,對於沒有找到類的用戶,請確保在調試之前檢查編譯器!