Question

I have a custom grid that shows all the CMS Blocks. When I use the search bar in the grid to filter out a title it redirects me to a 404 page. Is there something wrong with my grid to cause the redirect to an unknown page?

Also, not sure if it matters but this is happening on Enterprise Edition 1.12. I have another instance that is EE-1.13, which this is not an issue.

class TP_CustomApp_Block_Adminhtml_Glcmsblock_Grid extends Mage_Adminhtml_Block_Widget_Grid {

      public function __construct() {
        parent::__construct();
        $this->setId('glcmsblockGrid');
        $this->setDefaultSort('entity_id');
        $this->setDefaultDir('DESC');
        $this->setSaveParametersInSession(true);
        $this->setVarNameFilter('product_filter');
      }

      protected function _prepareCollection() {
        $store =  $this->getRequest()->getParam('store', '');
        Mage::getSingleton('core/session')->unsObjectType();
        Mage::getSingleton('core/session')->setObjectType(‘cms/block’);
        $collection = Mage::getModel('cms/block')->getCollection()->addStoreFilter($store->getId());
        $this->setCollection($collection);
        return parent::_prepareCollection();
      }

      protected function _prepareColumns() {

        $this->addColumn('title', array(
            'header' => Mage::helper('cms')->__('Title'),
            'align' => 'left',
            'index' => 'title',
            'width' => '25%',
        ));

        $this->addColumn('identifier', array(
            'header' => Mage::helper('cms')->__('Identifier'),
            'align' => 'left',
            'index' => 'identifier',
            'width' => '20%',
        ));

        …

        return parent::_prepareColumns();
      }

      public function getGridUrl() {
        return $this->getUrl('*/*', array('_current' => true));
      }

      public function getRowUrl($row) {
        return '"';
      }

      protected function _prepareMassaction() {
        $this->setMassactionIdField('entity_id');
        $this->getMassactionBlock()->setFormFieldName('gl_block_ids[]');
        $this->getMassactionBlock()->addItem('add', array(
            'label' => ‘Do some stuff’,
            'url' => $this->getUrl('*/*/massAdd'),
        ));
        return $this;
      }

}

Controller:

class TP_CustomApp_Adminhtml_GlcategoryController extends Mage_Adminhtml_Controller_Action {

  public function indexAction() {
    $this->loadLayout();
    $this->_setActiveMenu(‘MyApp/do_something’);
    $this->renderLayout();
  }

  public function gridAction(){
    $this->loadLayout();
    $this->getResponse()->setBody(
        $this->getLayout()->createBlock('MyApp/adminhtml_glcategory_grid')->toHtml()
    );
  }

  public function filterAction() {
    $post = $this->getRequest()->getPost();
    $radio = $post['filter'];
    Mage::getSingleton('core/session')->unsCategoryFilter();
    Mage::getSingleton('core/session')->setCategoryFilter($radio);
    $store = $post['store_id'];
    if ($store != '') {
      $this->_redirect('MyApp/adminhtml_glcategory', array('_query' => array('store' => $store)));
      return $this;
    }
    else {
      $this->_redirect('*/*');
      return $this;
    }
  }

  public function massAddAction() {
    $post = $this->getRequest()->getPost();
    $selected_category_ids = $post['gl_category_ids'];
    if (count($selected_category_ids) > 0) {
      // do some stuff with the ids
      return $this;
    }
    else {
      Mage::getSingleton('adminhtml/session')->addError('Please select a record.');
      $this->_redirect('*/*');
      return $this;
    }
  }

}
Was it helpful?

Solution

The action name is missing in your getGridUrl() method

public function getGridUrl() { 
      return $this->getUrl('*/*/grid', array('_current' => true)); 
} 

Edit : Change your gridAction() like below

public function gridAction(){
    $this->loadLayout();
    $this->renderLayout();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top