2

Not sure how to figure out this error, I've been googling for a week and I can't seem to find a solution. Any ideas?

exception 'Mage_Core_Exception' with message 'Invalid block type: Couponvalidator_Adminhtml_Couponvalidator' in /home/xxxxxxx/public_html/app/Mage.php:594
Stack trace:
#0 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Model/Layout.php(495): Mage::throwException('Invalid block t...')
#1 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Model/Layout.php(437): Mage_Core_Model_Layout->_getBlockInstance('Couponvalidator...', Array)
#2 /home/xxxxxxx/public_html/app/code/local/Gclone/Couponvalidator/controllers/Adminhtml/CouponvalidatorController.php(32): Mage_Core_Model_Layout->createBlock('Couponvalidator...')
#3 /home/xxxxxxx/public_html/app/code/local/Gclone/Couponvalidator/controllers/Adminhtml/CouponvalidatorController.php(37): Gclone_Couponvalidator_Adminhtml_CouponvalidatorController->_initAction()
#4 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(419): Gclone_Couponvalidator_Adminhtml_CouponvalidatorController->indexAction()
#5 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index')
#6 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#7 /home/xxxxxxx/public_html/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#8 /home/xxxxxxx/public_html/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#9 /home/xxxxxxx/public_html/index.php(87): Mage::run('', 'store')
#10 {main}

Thanks

That's the config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Gclone_Couponvalidator>
            <version>0.1.0</version>
        </Gclone_Couponvalidator>
    </modules>
    <frontend>
        <routers>
            <couponvalidator>
                <use>standard</use>
                <args>
                    <module>Gclone_Couponvalidator</module>
                    <frontName>couponvalidator</frontName>
                </args>
            </couponvalidator>
        </routers>
        <layout>
            <updates>
                <couponvalidator>
                    <file>couponvalidator.xml</file>
                </couponvalidator>
            </updates>
        </layout>
    </frontend>
    <admin>
        <routers>
            <couponvalidator>
                <use>admin</use>
                <args>
                    <module>Gclone_Couponvalidator</module>
                    <frontName>couponvalidator</frontName>
                </args>
            </couponvalidator>
        </routers>
    </admin>
    <adminhtml>
<!--        <menu>
            <couponvalidator module="couponvalidator">
                <title>Couponvalidator</title>
                <sort_order>71</sort_order>               
                <children>
                    <items module="couponvalidator">
                        <title>Manage Items</title>
                        <sort_order>0</sort_order>
                        <action>couponvalidator/adminhtml_couponvalidator</action>
                    </items>
                </children>
            </couponvalidator>
        </menu>-->

        <layout>
            <updates>
                <couponvalidator>
                    <file>couponvalidator.xml</file>
                </couponvalidator>
            </updates>
        </layout>
    </adminhtml>   
    <global>
        <models>
            <couponvalidator>
                <class>Gclone_Couponvalidator_Model</class>
                <resourceModel>couponvalidator_mysql4</resourceModel>
            </couponvalidator>
            <couponvalidator_mysql4>
                <class>Gclone_Couponvalidator_Model_Mysql4</class>
                <entities>
                    <couponvalidator>
                        <table>couponvalidator</table>
                    </couponvalidator>
                </entities>
            </couponvalidator_mysql4>
        </models>
        <resources>
            <couponvalidator_setup>
                <setup>
                    <module>Gclone_Couponvalidator</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </couponvalidator_setup>
            <couponvalidator_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </couponvalidator_write>
            <couponvalidator_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </couponvalidator_read>
        </resources>
        <blocks>
            <couponvalidator>
                <class>Gclone_Couponvalidator_Block</class>
            </couponvalidator>
        </blocks>
        <helpers>
            <couponvalidator>
                <class>Gclone_Couponvalidator_Helper</class>
            </couponvalidator>
        </helpers>
    </global>
</config>

The CouponvalidatorController.php

class Gclone_Couponvalidator_Adminhtml_CouponvalidatorController extends Mage_Adminhtml_Controller_Action
{

protected function _initAction() {
         $this->_title($this->__('Reports'))
         ->_title($this->__('Deals'))
         ->_title($this->__('Deals Ordered'));
    $this->loadLayout()
        ->_setActiveMenu('couponvalidator/items')
        ->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'))
             ->_addContent($this->getLayout()->createBlock('Couponvalidator_Adminhtml_Couponvalidator'));
    return $this;
}   

public function indexAction() {
    $this->_initAction()
        ->renderLayout();
}

public function editAction() {
    $id     = $this->getRequest()->getParam('id');
    $model  = Mage::getModel('couponvalidator/couponvalidator')->load($id);

    if ($model->getId() || $id == 0) {
        $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
        if (!empty($data)) {
            $model->setData($data);
        }

        Mage::register('couponvalidator_data', $model);

        $this->loadLayout();
        $this->_setActiveMenu('couponvalidator/items');

        $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
        $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));

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

        $this->_addContent($this->getLayout()->createBlock('couponvalidator/adminhtml_couponvalidator_edit'))
            ->_addLeft($this->getLayout()->createBlock('couponvalidator/adminhtml_couponvalidator_edit_tabs'));

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

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

public function saveAction() {
    if ($data = $this->getRequest()->getPost()) {

        if(isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
            try {   
                /* Starting upload */   
                $uploader = new Varien_File_Uploader('filename');

                // Any extention would work
                $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
                $uploader->setAllowRenameFiles(false);

                // Set the file upload mode 
                // false -> get the file directly in the specified folder
                // true -> get the file in the product like folders 
                //  (file.jpg will go in something like /media/f/i/file.jpg)
                $uploader->setFilesDispersion(false);

                // We set media as the upload dir
                $path = Mage::getBaseDir('media') . DS ;
                $uploader->save($path, $_FILES['filename']['name'] );

            } catch (Exception $e) {

            }

            //this way the name is saved in DB
            $data['filename'] = $_FILES['filename']['name'];
        }


        $model = Mage::getModel('couponvalidator/couponvalidator');     
        $model->setData($data)
            ->setId($this->getRequest()->getParam('id'));

        try {
            if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
                $model->setCreatedTime(now())
                    ->setUpdateTime(now());
            } else {
                $model->setUpdateTime(now());
            }   

            $model->save();
            Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('couponvalidator')->__('Item was successfully saved'));
            Mage::getSingleton('adminhtml/session')->setFormData(false);

            if ($this->getRequest()->getParam('back')) {
                $this->_redirect('*/*/edit', array('id' => $model->getId()));
                return;
            }
            $this->_redirect('*/*/');
            return;
        } catch (Exception $e) {
            Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
            Mage::getSingleton('adminhtml/session')->setFormData($data);
            $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
            return;
        }
    }
    Mage::getSingleton('adminhtml/session')->addError(Mage::helper('couponvalidator')->__('Unable to find item to save'));
    $this->_redirect('*/*/');
}

public function deleteAction() {
    if( $this->getRequest()->getParam('id') > 0 ) {
        try {
            $model = Mage::getModel('couponvalidator/couponvalidator');

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

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

public function massDeleteAction() {
    $couponvalidatorIds = $this->getRequest()->getParam('couponvalidator');
    if(!is_array($couponvalidatorIds)) {
        Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
    } else {
        try {
            foreach ($couponvalidatorIds as $couponvalidatorId) {
                $couponvalidator = Mage::getModel('couponvalidator/couponvalidator')->load($couponvalidatorId);
                $couponvalidator->delete();
            }
            Mage::getSingleton('adminhtml/session')->addSuccess(
                Mage::helper('adminhtml')->__(
                    'Total of %d record(s) were successfully deleted', count($couponvalidatorIds)
                )
            );
        } catch (Exception $e) {
            Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
        }
    }
    $this->_redirect('*/*/index');
}

public function massStatusAction()
{
    $couponvalidatorIds = $this->getRequest()->getParam('couponvalidator');
    if(!is_array($couponvalidatorIds)) {
        Mage::getSingleton('adminhtml/session')->addError($this->__('Please select item(s)'));
    } else {
        try {
            foreach ($couponvalidatorIds as $couponvalidatorId) {
                $couponvalidator = Mage::getSingleton('couponvalidator/couponvalidator')
                    ->load($couponvalidatorId)
                    ->setStatus($this->getRequest()->getParam('status'))
                    ->setIsMassupdate(true)
                    ->save();
            }
            $this->_getSession()->addSuccess(
                $this->__('Total of %d record(s) were successfully updated', count($couponvalidatorIds))
            );
        } catch (Exception $e) {
            $this->_getSession()->addError($e->getMessage());
        }
    }
    $this->_redirect('*/*/index');
}

public function exportCsvAction()
{
    $fileName   = 'couponvalidator.csv';
    $content    = $this->getLayout()->createBlock('couponvalidator/adminhtml_couponvalidator_grid')
        ->getCsv();

    $this->_sendUploadResponse($fileName, $content);
}

public function exportXmlAction()
{
    $fileName   = 'couponvalidator.xml';
    $content    = $this->getLayout()->createBlock('couponvalidator/adminhtml_couponvalidator_grid')
        ->getXml();

    $this->_sendUploadResponse($fileName, $content);
}

protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
{
    $response = $this->getResponse();
    $response->setHeader('HTTP/1.1 200 OK','');
    $response->setHeader('Pragma', 'public', true);
    $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
    $response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
    $response->setHeader('Last-Modified', date('r'));
    $response->setHeader('Accept-Ranges', 'bytes');
    $response->setHeader('Content-Length', strlen($content));
    $response->setHeader('Content-type', $contentType);
    $response->setBody($content);
    $response->sendResponse();
    die;
}
}
7
  • can you put Gclone_Couponvalidator module config.xml.it may be issue here
    – Amit Bera
    Commented Sep 7, 2014 at 13:09
  • @t2time, Are you still using Coupon Validator module or you have removed/disabled it?
    – MTM
    Commented Sep 7, 2014 at 13:21
  • Thanks for reply guys,@MTM yes i am still using it
    – t2time
    Commented Sep 7, 2014 at 13:31
  • can you put CouponvalidatorController.php code
    – Amit Bera
    Commented Sep 7, 2014 at 13:47
  • </menu>--> change to </menu> --> it need space between </menu> -->
    – Amit Bera
    Commented Sep 7, 2014 at 13:49

2 Answers 2

1

there are issue in

->createBlock('Couponvalidator_Adminhtml_Couponvalidator')

should be

->createBlock('couponvalidator/adminhtml_couponvalidator')

in

createBlock you need call a block  in logic

'blocktype/rest_of_file_path'

couponvalidator/adminhtml_couponvalidator

couponvalidator is as block type which define in config.xml

 <blocks>
            <couponvalidator>
                <class>Gclone_Couponvalidator_Block</class>
            </couponvalidator>
        </blocks>

Here couponvalidator is a block type and it class define in xml Gclone_Couponvalidator_Block

and adminhtml_couponvalidator is call rest of class Adminhtml_Couponvalidator.

if you run ->createBlock('couponvalidator/adminhtml_couponvalidator') code then magento is class Gclone_Couponvalidator_Block_Adminhtml_Couponvalidator

1

Change the _initAction() function of controller file CouponvalidatorController.php as following and focus on the line ->_addContent($this->getLayout()->createBlock('couponvalidator/adminhtml_couponvalidator'));

protected function _initAction() {
     $this->_title($this->__('Reports'))
     ->_title($this->__('Deals'))
     ->_title($this->__('Deals Ordered'));
$this->loadLayout()
    ->_setActiveMenu('couponvalidator/items')
    ->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'))
         ->_addContent($this->getLayout()->createBlock('couponvalidator/adminhtml_couponvalidator'));
     return $this;
} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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