0

Need some assistance here guys,

I've created an Admin module which displays data from a database table. There are two tables, one for UK (data) and the other is for ROI (data_roi). I have been able to show the list in a Grid for UK fine but when I select the ROI list from the navigation menu it displays a blank screen and I can figure out why???

Here is my Grid.php for the first list

<?php

class MyCompany_MyModule_Block_Adminhtml_Cancellation_Reason_Grid extends Mage_Adminhtml_Block_Widget_Grid 
{
  public function __construct()
  {
    parent::__construct();
    $this->setId('cancellation_reasonGrid');
    // database table primary key as default sort
    $this->setDefaultSort('id');
    // default sort order
    $this->setDefaultDir('ASC');
    $this->setSaveParametersInSession(true);
    $this->setUseAjax(true);

  }

  protected function _prepareCollection()
  {
    $oCollection = Mage::getModel('callcenter/cancellation_reason')->getCollection();
    $this->setCollection($oCollection);

    return parent::_prepareCollection();
  }

  protected function _prepareColumns()
  {
    $this->addColumn('id',
      array(
        'header'  => Mage::helper('callcenter')->__('ID'),
        'align'   => 'right',
        'width'   => '50px',
        'index'   => 'id'
      )
    );

    $this->addColumn('reason',
      array(
        'header'  => Mage::helper('callcenter')->__('Reason'),
        'align'   => 'left',
        'index'   => 'reason'
      )
    );



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

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

And the second list

<?php

class Mycompany_MyModule_Block_Adminhtml_Roi_Cancellation_Reason_Grid extends Mage_Adminhtml_Block_Widget_Grid 
{
  public function __construct()
  {
    parent::__construct();
    $this->setId('roi_cancellation_reasonGrid');
    // database table primary key as default sort
    $this->setDefaultSort('id');
    // default sort order
    $this->setDefaultDir('ASC');
    $this->setSaveParametersInSession(true);
  }

  protected function _prepareCollection()
  {
    $Collection = Mage::getModel('callcenter/cancellation_reason_roi')->getCollection();
    $this->setCollection($Collection);

    return parent::_prepareCollection();
  }

  protected function _prepareColumns()
  {
    $this->addColumn('id',
      array(
        'header'  => Mage::helper('callcenter')->__('ID'),
        'align'   => 'right',
        'width'   => '50px',
        'index'   => 'id'
      )
    );

    $this->addColumn('reason_roi',
      array(
        'header'  => Mage::helper('callcenter')->__('Reason'),
        'align'   => 'left',
        'index'   => 'reason_roi'
      ));



    return parent::_prepareColumns();
  }

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

I honestly don't think the syntax for my Grid.php files are incorrect. I think it has something to do with my controller for ROI

<?php

class MyCompany_MyModule_Adminhtml_Roi_Cancellation_ReasonController extends Mage_Adminhtml_Controller_Action
{
  public function _initAction()
  {
      $act = $this->getRequest()->getActionName();
      $this->loadLayout();
      return $this;
  }

  public function listAction()
  {
    $this->_title($this->__('CallCenter'))
           ->_title($this->__('Cancellation Reasons'));

    $this->_initAction()
          ->_setActiveMenu('callcenter/roi_cancellation_reason')
          //->_addContent($this->getLayout()->createBlock('callcenter/adminhtml_cancellation_reason_grid'))
          ->renderLayout();
  }

  public function newAction()
  {
      $this->_forward('edit');
  }

  public function indexAction()
  {
    $this->_forward('list');
  }

  public function editAction()
  {
      $CancellationReasonId     = $this->getRequest()->getParam('id');
      $CancellationReasonModel  = Mage::getModel('callcenter/roi_cancellation_reason')->load($CancellationReasonId);

        if ($CancellationReasonModel->getId() || $CancellationReasonModelId == 0) {

            Mage::register('roi_cancellation_reason_data', $CancellationReasonModel);

            $this->loadLayout();
            $this->_setActiveMenu('callcenter/roi_cancellation_reason');

          $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Cancellation'), Mage::helper('adminhtml')->__('Cancellation'));

          $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);

          $this->_addContent($this->getLayout()->createBlock('callcenter/adminhtml_roi_cancellation_reason_edit'));
              // ->_addLeft($this->getLayout()->createBlock('callcenter/adminhtml_cancellation_reason_edit_tabs'));

          $this->renderLayout();
      } else {
          Mage::getSingleton('adminhtml/session')->addError(Mage::helper('callcenter')->__('Cancellation reason does not exist'));
          $this->_redirect('*/*/');
      }
  }

  public function saveAction()
  {
      if ( $this->getRequest()->getPost() ) {
          try {
              $postData = $this->getRequest()->getPost();

              $CancellationReasonModel = Mage::getModel('callcenter/roi_cancellation_reason');

              $CancellationReasonModel->setId($this->getRequest()->getParam('id'))
                  ->setReason($postData["reason"]);

              $CancellationReasonModel->save();

              Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Cancellation reason was successfully saved'));
              Mage::getSingleton('adminhtml/session')->setCancellationReasonData(false);

                $this->_redirect('*/*/');
              return;
          } catch (Exception $e) {
              Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
              Mage::getSingleton('adminhtml/session')->setCancellationReasonData($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 {
              $CancellationReasonModel = Mage::getModel('callcenter/roi_cancellation_reason');

              $CancellationReasonModel->setId($this->getRequest()->getParam('id'))
                  ->delete();

              Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Cancellation reason was 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('*/*/');
  }
}

I'm trying to figure out what i've missed but haven't found it yet. Does anyone know how to show data from two separate DB tables using either one Grid Or Two separate Grids. The reason I am using two Grids is because i need the ability to add or delete data from each table via the admin but again if anyone knows a better way to do this please assist as I think I am making this more complicated than it needs to be...

Thanks guys!

Exception Log shows this

exception 'Mage_Core_Exception' with message 'Invalid block type: MyCompany_MyModule_Block_Adminhtml_Roi_Cancellation_Reason' in /var/www/uk-dev3.mywebsite.com/htdocs/app/Mage.php:594

Any ideas on how to correct this?

1

I see that in MyCompany_MyModule_Adminhtml_Roi_Cancellation_ReasonController::listAction

addContent is commented and probably this why you see a blank page.

$this->_initAction()
          ->_setActiveMenu('callcenter/roi_cancellation_reason')
          //->_addContent($this->getLayout()->createBlock('callcenter/adminhtml_cancellation_reason_grid'))
          ->renderLayout();
| improve this answer | |
  • Thanks for noticing, I've kept that commented out as it is also commented out in the first controller which works fine... I've looked in the exception log and seen that one of my blocks are invalid. – user1704524 Jul 2 '13 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.