I am trying to create a custom module.When i click a module menu,empty grid is displaying.Log is not showing any errors
Grid.php
class Training_Banners_Block_Adminhtml_Banners_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('bannersGrid');
$this->setDefaultDir('ASC');
$this->setDefaultSort('banner_id');
$this->setSaveParamatersInSession(true);
}
protected function _prepareCollection()
{
$collection=Mage::getModel('banners/manage')->getCollection();
$this->setCollection($collection);
Mage::log(var_dump($collection));
return $collection;
}
protected function _prepareColumns()
{
$this->addColumn('banner_id', array(
'header' => Mage::helper('banners')->__('ID'),
'align' =>'right',
'width' => '50px',
'index' => 'banner_id'
));
$this->addColumn('name', array(
'header' => Mage::helper('banners')->__('Name'),
'align' =>'left',
'index' => 'name'
));
return parent::_prepareColumns();
}
}
banners.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<adminhtml_banners_index>
<reference name="content">
<block type="banners/adminhtml_banners" name="training.banners" />
</reference>
</adminhtml_banners_index>
</layout>
Controller
<?php
class Training_Banners_Adminhtml_BanneradminController extends Mage_Adminhtml_Controller_Action
{
public function _initAction()
{
$this->loadLayout()->_setActiveMenu('banners/banners')
->_addBreadcrumb(Mage::helper('adminhtml')->__('Banners Manager'), Mage::helper('adminhtml')->__('Banners Manager'));
return $this;
}
public function indexAction()
{
$this->_initAction();
$this->loadLayout();
$this->_addContent($this->getLayout()->createBlock('banners/adminhtml_banners'));
$this->renderLayout();
}
}
First Please clear your cache and then logout and login.
Also please check the config.xml file ,whether the block and other declarations are same..
Related
i have been following this to create an admin grid view. Grid works fine but when i try to load form to edit or delete or save my entries there is no save and delete button in my form container see here https://www.dropbox.com/s/odk79gsvufpj9j9/Screenshot%20from%202015-08-28%2014%3A37%3A08.png?dl=0
here is my Edit.php
class Best_Test_Block_Adminhtml_Test_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{
public function __construct()
{
parent::_construct();
$this->_objectId = 'id';
$this->_blockGroup = 'test';
$this->_controller = 'adminhtml_test';
$this->_updatebutton('save', 'label', 'save user');
$this->_updatebutton('delete', 'label', 'delete user');
}
public function getHeaderText()
{
if (Mage::registry('test_data')&&Mage::registry('test_data')->getId()) {
return 'Edit user '.$this->htmlEscape(Mage::regisrty('test_data')->getTitle()).'<br/>';
}else{
return 'Add a user';
}
}
}
here is my indexController.php in Adminhtml
class Best_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();
}
public function editAction()
{
$testId = $this->getRequest()->getParam('id');
$testModel = Mage::getModel('test/test')->load($testId);
if ($testModel->getId() || $testId == 0) {
Mage::register('test_data', $testModel);
$this->loadLayout();
$this->_setActiveMenu('test/set_time');
$this->_addBreadcrumb('test Manager', 'test Manager');
$this->_addBreadcrumb('Test Description', 'Test Description');
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
$this->_addContent($this->getLayout()->createBlock('test/adminhtml_test_edit'))->_addLeft($this->getLayout()->createBlock('test/adminhtml_test_edit_tabs'));
$this->renderLayout();
}else{
Mage::getSingleton('adminhtml/session')->addError('Test does not exist!');
$this->_redirect('*/*/');
}
}
public function newAction()
{
$this->_forward('edit');
}
public function saveAction()
{
if ($this->getRequest()->getPost()) {
try{
$postData = $this->getRequest()->getPost();
$testModel = Mage::getModel('test/test');
if ($this->getRequest()->getParam('id') <= 0) {
$testModel->setCreatedTime(Mage::getSingleton('core/date')->gmtDate());
$testModel->addData($postData)->setUpdateTime(Mage::getSingleton('core/date')->gmtDate())->setId($this->getRequest()->getParam('id'))->save();
Mage::getSingleton('adminhtml/session')->addSuccess('successfully saved');
Mage::getSingleton('adminhtml/session')->settestData(false);
$this->_redirect('*/*/');
return;
}
} catch (Exception $e){
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
Mage::getSingleton('adminhtml/session')->settestData($this->getRequest()->getPost());
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
return ;
}
}
$this->_redirect('*/*/');
}
public function deleteAction()
{
if ($this->getRequest()->getParam('id') > 0) {
try{
$testModel = Mage::getModel('test/test');
$testModel->setId($this->getRequest()->getParam('id'))->delete();
Mage::getSingleton('adminhtml/session')->addSuccess('Successfully deleted');
$this->_redirect('*/*/');
} catch (Exception $e){
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
}
}
$this->_redirect('*/*/');
}
}
here is Form.php in Adminhtml/Test/Edit
class Best_Test_Block_Adminhtml_Test_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);
$form->setForm($form);
return parent::_prepareForm();
}
}
here is Tabs.php in Adminhtml/Test/Edit
class Best_Test_Block_Adminhtml_Test_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
{
public function __construct()
{
parent::__construct();
$this->setId('test_tabs');
$this->setDestElementId('edit_form');
$this->setTitle('Information of User');
}
protected function _beforeToHtml()
{
$this->addTab('form_section', array(
'label' => 'User information',
'title' => 'User information',
'content' => $this->getLayout()->createBlock('test/adminhtml_test_edit_tab_form')->toHtml()
));
return parent::_beforeToHtml()
; }
}
here is Form.php in Adminhtml/Test/Edit/Tab
class Best_Test_Block_Adminhtml_Test_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareform()
{
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('test_form', array('legend'=>'ref information'));
$fieldset->addField('name', 'text', array(
'label' => 'name',
'class' => 'required-entry',
'required' => 'true',
'name' => 'name',
));
$fieldset->addField('email', 'text', array(
'label' => 'email',
'class' => 'required-entry',
'required' => 'true',
'name' => 'email',
));
$fieldset->addField('password', 'password', array(
'label' => 'password',
'class' => 'required-entry',
'required' => 'true',
'name' => 'password',
));
if (Mage::registry('test_data')) {
$form->setValues(Mage::registry('test_data')->getData());
}
return parent::_prepareform();
}
}
And here is my test.xml in app/design/adminhtml/default/default/layout
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
<test_adminhtml_index_index>
<reference name="content">
<block type="test/adminhtml_grid" name="test" />
</reference>
</test_adminhtml_index_index>
</layout>
why is save and delete missing from my form container?
Sorry if question is not well phrased, i am a noob magento user.
I've been attempting to add a "Status" column in the Orders grid that's shown when you view the Customer Information -> Orders tab.
I've been able to add the column, and the filter populates with the correct status values, but it breaks the default sorting and you can't filter by any item or sort.
I know there's probably a much better way of adding the column, but all the examples I found related to the main Orders table and I couldn't figure out how to modify it for this use case.
Here's my extension code - in /Pnp/Customer/Block/Customer/Edit/Tab/Orders.php
<?php
class Pnp_Customer_Block_Customer_Edit_Tab_Orders extends Mage_Adminhtml_Block_Customer_Edit_Tab_Orders
{
public function __construct()
{
parent::__construct();
$this->setId('customer_orders_grid');
$this->setUseAjax(true);
$this->setDefaultSort('created_at');
$this->setDefaultDir('DESC');
$this->setSaveParametersInSession(true);
}
protected function _prepareCollection()
{
$collection = Mage::getResourceModel('sales/order_grid_collection')
->addFieldToSelect('entity_id')
->addFieldToSelect('increment_id')
->addFieldToSelect('customer_id')
->addFieldToSelect('created_at')
->addFieldToSelect('grand_total')
->addFieldToSelect('order_currency_code')
->addFieldToSelect('store_id')
->addFieldToSelect('billing_name')
->addFieldToSelect('shipping_name')
->addFieldToSelect('status')
->addFieldToFilter('customer_id', Mage::registry('current_customer')->getId())
->setIsCustomerMode(true);
$this->setCollection($collection);
return $this;
}
protected function _prepareColumns()
{
parent::_prepareColumns();
$this->addColumn('status', array(
'header' => Mage::helper('sales')->__('Status'),
'index' => 'status',
'type' => 'options',
'width' => '70px',
'options' => Mage::getSingleton('sales/order_config')->getStatuses()
));
return parent::_prepareColumns();
}
}
Thanks in advance for any help you can offer!
Many thanks to the answers so far.
I've nearly got there with a combination of Harit and Emipro Technologies answers, here's what I have so far:
etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Pnp_Customer>
<version>0.4.0</version>
</Pnp_Customer>
</modules>
<global>
<models>
<pnp_statusgrid>
<class>Pnp_Customer_Model</class>
</Pnp_statusgrid>
</models>
</global>
<adminhtml>
<events>
<core_block_abstract_prepare_layout_before>
<observers>
<statusgrid_column_append>
<type>model</type>
<class>Pnp_Customer_Model_Observer</class>
<method>appendCustomColumn</method>
</statusgrid_column_append>
</observers>
</core_block_abstract_prepare_layout_before>
</events>
</adminhtml>
</config>
Model/Observer.php
<?php
class Pnp_Customer_Model_Observer extends Varien_Event_Observer
{
/**
* Adds column to admin customers grid
*
* #param Varien_Event_Observer $observer
* #return Pnp_Customer_Model_Observer
*/
public function appendCustomColumn(Varien_Event_Observer $observer)
{
$block = $observer->getBlock();
if (!isset($block)) {
return $this;
}
if ($block->getType() == 'adminhtml/customer_edit_tab_orders') {
/* #var $block Mage_Adminhtml_Block_Customer_Grid */
$block->addColumn('status', array(
'header' => Mage::helper('customer')->__('Status'),
'type' => 'options',
'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
'width' => '70px',
'index' => 'status',
'renderer' => 'Pnp_Customer_Block_Customer_Edit_Tab_Renderer_Status',
}
}
}
Block/Customer/Edit/Tab/Orders.php
<?php
class Pnp_Customer_Block_Customer_Edit_Tab_Orders extends Mage_Adminhtml_Block_Customer_Edit_Tab_Orders
{
protected function _prepareCollection()
{
$collection = Mage::getResourceModel('sales/order_grid_collection')
->addFieldToSelect('entity_id')
->addFieldToSelect('increment_id')
->addFieldToSelect('customer_id')
->addFieldToSelect('created_at')
->addFieldToSelect('grand_total')
->addFieldToSelect('order_currency_code')
->addFieldToSelect('store_id')
->addFieldToSelect('billing_name')
->addFieldToSelect('shipping_name')
->addFieldToSelect('status')
->addFieldToFilter('customer_id', Mage::registry('current_customer')->getId())
->setIsCustomerMode(true);
$this->setCollection($collection);
return $this;
}
}
Block/Customer/Edit/Tab/Renderer/status.php
<?php
class Pnp_Customer_Block_Customer_Edit_Tab_Renderer_Status extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
public function render(Varien_Object $row)
{
if (!$value = $this->getColumn()->getIndex()){
return $this;
}
$value = $row->getData('increment_id');
$order = Mage::getModel('sales/order')->loadByIncrementId($value);
return '<span >'.$order['status']'</span>';
}
}
?>
Everything is working except the column shows the status name as underscored, i.e. payment_pending. I looked at the object being returned and can't see the label version. As a final thing to get the above finished, would anyone be able to point me in the right direction to print the human readable version of the attribute?
Final Edit:
I managed to figure it out - I changed:
return '<span >'.$order['status']'</span>';
to
return '<span >'.$order->getStatusLabel().'</span>';
This is definately work add renderer
change your column by
$this->addColumn('status', array(
'header' => Mage::helper('customer')->__('Status'),
'index' => 'status',
'type' => 'options',
'options' => $this->_getorderstatus(),
'renderer' => 'Pnp_Customer_Block_Customer_Edit_Renderer_Status',
));
Add new function in same file
protected function _getorderstatus(){
$ordstatus = (array) Mage::getModel('sales/order_status')->getResourceCollection()->getData();
$orderstatus=array();
foreach($ordstatus as $item){
$orderstatus[$item['status']]=$item['label'];
}
return $orderstatus;
}
status.php put function like
public function render(Varien_Object $row)
{
if (!$value = $this->getColumn()->getIndex()){
return $this;
}
$value = $row->getData('increment_id');
$order = Mage::getModel('sales/order')->loadByIncrementId($value);
return '<span >'.$order['status'].'</span>';
}
An easier and reliable way to achieve this is through observer.
Create a Module
Inside app/code/local/My/Module/etc/config.xml
<global>
<models>
<my_customgrid>
<class>My_Module_Model</class>
</my_customgrid>
</models>
</global>
<adminhtml>
<events>
<core_block_abstract_prepare_layout_before>
<observers>
<customgrid_column_append>
<type>model</type>
<class>My_Module_Model_Observer</class>
<method>appendCustomColumn</method>
</customgrid_column_append>
</observers>
</core_block_abstract_prepare_layout_before>
</events>
</adminhtml>
What it does is, it allows you to observe the block before its layout is prepared.
Create a file called Observer.php for your module and write down following:
class My_Module_Model_Observer extends Varien_Event_Observer {
/**
*
* #param Varien_Event_Observer $observer
* #return \My_Module_Model_Observer
*/
public function appendCustomColumn(Varien_Event_Observer $observer) {
$block = $observer->getBlock();
if (!isset($block)) {
return $this;
}
if ($block->getType() == 'adminhtml/customer_grid') {
/* #var $block Mage_Adminhtml_Block_Customer_Grid */
$block->addColumnAfter('field', array(
'header' => 'Your Field',
'type' => 'text',
'index' => 'field',
), 'email');
}
}
}
Follow this link for more information:
http://www.atwix.com/magento/add-column-to-customers-grid-alternative-way/
Hope it helps.
Hello I've trying to create a grid serializer. Upon clicking the tab in Admin it's displaying correctly.
But when in grid I change the select field from Yes to Any to find all the records. It gives the Foreach error(Invalid argument supplied for foreach).
Layout:
<manager_adminhtml_manager_category>
<block type="core/text_list" name="root" output="toHtml">
<block type="manager/adminhtml_manager_edit_tab_category" name="categories.grid"/>
<block type="adminhtml/widget_grid_serializer" name="grid_serializer">
<reference name="grid_serializer">
<action method="initSerializerBlock">
<grid_block_name>categories.grid</grid_block_name>
<data_callback>getSelectedCategories</data_callback>
<hidden_input_name>links[category]</hidden_input_name>
<reload_param_name>category</reload_param_name>
</action>
<action method="addColumnInputName">
<input_name>position</input_name>
</action>
</reference>
</block>
</block>
</manager_adminhtml_manager_category>
<manager_adminhtml_manager_categorygrid>
<block type="core/text_list" name="root" output="toHtml">
<block type="manager/adminhtml_manager_edit_tab_category" name="categories.grid"/>
</block>
</manager_adminhtml_manager_categorygrid>
controller
class Excellence_Manager_Adminhtml_ManagerController extends Mage_Adminhtml_Controller_action
{
public function categoryAction(){
$this->loadLayout();
$this->getLayout()->getBlock('categories.grid')->setCategory($this->getRequest()->getPost('category',null));
$this->renderLayout();
}
public function categorygridAction(){
$this->loadLayout();
$this->getLayout()->getBlock('categories.grid')
->setCategory($this->getRequest()->getPost('category', null));
$this->renderLayout();
}
block
<?php
class Excellence_Manager_Block_Adminhtml_Manager_Edit_Tab_Category extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('categoryGrid');
$this->setUseAjax(true); // Using ajax grid is important
$this->setDefaultSort('entity_id'); // default sort from the _prepareColoum below
$this->setDefaultFilter(array('in_producted'=>1)); // By default we have added a filter for the rows, that in_products value to be 1
$this->setSaveParametersInSession(false);
}
protected function _prepareCollection()
{
$collection = Mage::getResourceModel('catalog/category_collection');
$tm_id = $this->getRequest()->getParam('id');
if(!isset($tm_id)) {
$tm_id = 0;
}
Mage::getResourceModel('manager/cat')->addGridPosition($collection,$tm_id);
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _addColumnFilterToCollection($column)
{
// Set custom filter for in product flag
if ($column->getId() == 'in_producted') {
$ids = $this->_getSelectedCategories();
if (empty($ids)) {
$ids = 0;
}
if ($column->getFilter()->getValue()) {
$this->getCollection()->addFieldToFilter('entity_id', array('in'=>$ids));
} else {
if($ids) {
$this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$ids));
}
}
} else {
parent::_addColumnFilterToCollection($column);
}
return $this;
}
protected function _prepareColumns()
{
$this->addColumn('in_producted', array(
'header_css_class' => 'a-center',
'type' => 'checkbox',
'name' => 'customer',
'values' => $this->_getSelectedCategories(),
'align' => 'center',
'index' => 'entity_id'
));
$this->addColumn('entity_id', array(
'header' => Mage::helper('customer')->__('ID'),
'width' => '50px',
'index' => 'entity_id',
'type' => 'number',
));
$this->addColumn('name', array(
'header' => Mage::helper('customer')->__('Name'),
'index' => 'name'
));
$this->addColumn('is_active', array(
'header' => Mage::helper('customer')->__('Status'),
'width' => '150',
'index' => 'is_active'
));
return parent::_prepareColumns();
}
protected function _getSelectedCategories() // Used in grid to return selected customers values.
{
$categories = array_keys($this->getSelectedCategories());
return $categories;
}
public function getGridUrl()
{
return $this->_getData('grid_url') ? $this->_getData('grid_url') : $this->getUrl('*/*/categorygrid', array('_current'=>true));
}
public function getSelectedCategories()
{
// Categories Data
$tm_id = $this->getRequest()->getParam('id');
if(!isset($tm_id)) {
$tm_id = 0;
}
$collection = Mage::getModel('manager/cat')->getCollection();
$collection->addFieldToFilter('manager_id',$tm_id);
$catIds = array();
foreach($collection as $obj){
$catIds[$obj->getCategoryId()] = array('position'=>$obj->getPosition());
}
return $catIds;
}
}
Have you checked that the $collection isn't empty/has data? Could you var_dump($collection); before your foreach loop and post the output?
Try this by replacing:
$collection = Mage::getModel('manager/cat')->getCollection();
$collection->addFieldToFilter('manager_id',$tm_id);
with
$collection = Mage::getModel('manager/cat')->getCollection()->addFieldToSelect('*')->addFieldToFilter('manager_id',$tm_id);
If that doesn't work try adding $collection->load(); before your foreach loop.
How to override _prepareCollection and _prepareColumn from core to local. I want to add new column in a grid. How to do this?
protected function _prepareCollection()
{
$collection = Mage::getModel('players/players')->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('player_id', array(
'header' => Mage::helper('players')->__('ID'),
'align' =>'right',
'width' => '50px',
'index' => 'player_id',
));
$this->addColumn('name', array(
'header' => Mage::helper('players')->__('Name'),
'align' =>'left',
'index' => 'name',
));
return parent::_prepareColumns();
}
Well there are two ways to do it. The first, while easier is not preferred, is to "local include hack" it and move the grid from core/Mage/../.. to local/Mage../.. and simply make your changes are required.
The alternative is to do a rewrite of the file in a module config.xml:
<blocks>
<customadminhtml>
<class>Namespace_CustomAdminhtml_Block</class>
</customadminhtml>
<adminhtml>
<rewrite>
<sales_order_grid>Namespace_CustomAdminhtml_Block_Adminhtml_Sales_Order_Grid</sales_order_grid>
</rewrite>
</adminhtml>
</blocks>
In the rewritten file I would not both trying to override the "_prepareCollection" call. How are you going to call it and set the collection, logically, you can't insert your changes in there properly and still maintain original functionality. Instead I would override the "setCollection" method. By doing this you maintain the logic of the original _prepareCollection function and can insert your logic into the flow:
/**
* #brief Add customer_email to sales order
* #param Mage_Sales_Model_Resource_order_grid_collection $collection
*/
public function setCollection($collection)
{
/** #var Mage_Eav_Model_Config $eav */
$eav = Mage::getModel('eav/config');
$attribute = $eav->getAttribute('customer', 'customer_number');
$connection = $collection->getConnection();
$collection->join(array('sfo' => 'sales/order'), 'main_table.entity_id=sfo.entity_id', 'customer_email');
if ($attribute->getId()) {
$collection->getSelect()
->joinLeft(array('c' => $connection->getTableName('customer_entity_varchar')),
'main_table.customer_id = c.entity_id AND c.attribute_id = '.$attribute->getId(),
array('customer_number' => 'value'));
}
parent::setCollection($collection);
}
Finally, you can add the column by overriding the normal "_prepareColumns" function, just call the parent before hand:
public function _prepareColumns()
{
parent::_prepareColumns();
$this->addColumnAfter('customer_email', array(
'header' => Mage::helper('customer')->__('Customer Email'),
'width' => '50px',
'index' => 'customer_email',
), 'shipping_name');
$this->sortColumnsByOrder();
return $this;
}
I am trying to create a custom module in magento admin. I have reached the point where a new link has been added to the menu and by clicking on it, I can navigate to the index action of the controller of the module. But here I cannot see the grid, only the header text and the button which has been added in the block construct appear.
I can see that since this block extends the Mage_Adminhtml_Block_Widget_Grid_Container class, it will by itself add the grid block inside this module as its child.
And the Grid.php is included which I verified by printing out something in the overriden _prepareColumns method.
What am I missing here ?
These are the contents of the Grid.php file
class Book_Brands_Block_Adminhtml_Brands_Grid extends Mage_Adminhtml_Block_Widget_Grid {
public function __construct() {
parent::__construct();
$this->setId('brandsGrid');
$this->setDefaultSort('brands_id');
$this->setDefaultDir('ASC');
$this->setSaveParametersInSession(true);
}
protected function _prepareCollection() {
$collection = Mage::getModel('brands/brands')->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns() {
$this->addColumn('brands_id', array(
'header' => Mage::helper('brands')->__('ID'),
'align' =>'right',
'width' => '50px',
'index' => 'brands_id',
));
$this->addColumn('title', array(
'header'=> Mage::helper('brands')->__('Title'),
'align' =>'left',
'index' => 'title',
));
$this->addColumn('status', array(
'header'=> Mage::helper('brands')->__('Status'),
'align' => 'left',
'width' => '80px',
'index' => 'status',
'type' => 'options',
'options' => array(
1 => 'Enabled',
2 => 'Disabled',
),
));
$this->addColumn('action', array(
'header' => Mage::helper('brands')->__('Action'),
'width' => '100',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('brands')->__('Edit'),
'url' => array('base'=> '*/*/edit'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
return parent::_prepareColumns();
}
public function getRowUrl($row) {
return $this->getUrl('*/*/edit', array('id' => $row->getId()));
}
}
Thanks
PS. I have tried flushing the cache but no luck
From memory I think _prepareColumns() is called before _prepareCollection() so if there is an error in the collection the grid won't get rendered even though you have confirmed the columns method.
Part of parent::_prepareCollection() tries to estimate the number of pages from the collection's getSize() and getSelectCountSql() methods, I often forget to check those are producing sane results which trips me up. Make sure all logging is turned on and put the following in your .htaccess file:
php_flag display_errors on
SetEnv MAGE_IS_DEVELOPER_MODE true
Try seeing what query is being generated with these commands:
Mage::log((string)$collection->getSelect());
Mage::log((string)$collection->getSelectCountSql());
Looks like you have the grid blocks set up correctly. However, you still need to load the grid into the layout and render it. This can either be done in the adminhtml layout xml or in the controller.
In your /app/design/adminhtml/../layout/brands.xml:
<?xml version="1.0"?>
<layout>
<brands_index_index>
<reference name="content">
<block type="brands/brands_grid" name="brands_grid"></block>
</reference>
</brands_index_index>
</layout>
In your controller:
public function indexAction()
{
$this->loadLayout();
$this->_addContent(
$this->getLayout()->createBlock('brands/brands_grid','brands')
);
$this->renderLayout();
}
Please note that you have to modify the above to your particular implementation. I think the layout xml is harder to comprehend initially than the programmatic instantiation in the controller, however, in the long run, it leads to less code bloat.
Just had a quick view and the only thing I can see in your code is:
protected function _prepareCollection() {
$collection = Mage::getModel('brands/brands')->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
//Try to use it like this:
protected function _prepareCollection() {
$collection = Mage::getModel('brands/brands')->getCollection();
$this->setCollection($collection);
parent::_prepareCollection();
return $this;
}