0

After activate cache I got this error in controller:

Fatal error: Call to a member function getBlock() on string

Below is my controller action code:

public function loginAction()
{

if ($this->_getSession()->isLoggedIn()) {
    $this->_redirect('*/*/');
    return;
}
$this->getResponse()->setHeader('Login-Required', 'true');

$this->loadLayout();

$update = $this->getLayout()->getUpdate();
$update->addHandle('customer_account_login');
$this->loadLayoutUpdates();
$this->generateLayoutXml();
$this->generateLayoutBlocks();
$this->_isLayoutLoaded = true;

$blockList = $this->getLayout()->getBlock('customer_form_login');
$template = $blockList->getTemplate();
$blockChildBlock = $blockList->getChild();

$this->getLayout()->unsetBlock('customer_form_login');
$parentBlock = $this->getLayout()->createBlock('vendorpos/customer_form_login','customer_form_login')->setTemplate($template);

if($blockChildBlock){
    foreach($blockChildBlock as $childBlock){
        $this->getChildBlockLogin($parentBlock,$childBlock);
    }
}

$this->_initLayoutMessages('customer/session');
$this->_initLayoutMessages('catalog/session');
$this->renderLayout();
}
1
  • Try $this->getBlock('customer_form_login'); instead of $this->getLayout()->getBlock('customer_form_login');, let me know if it works for you – Rohit Kundale Feb 26 '16 at 5:35
0

Comment following code from action

/*$update = $this->getLayout()->getUpdate();
$update->addHandle('customer_account_login');
$this->loadLayoutUpdates();
$this->generateLayoutXml();
$this->generateLayoutBlocks();
$this->_isLayoutLoaded = true;*/

and created layout file in app\design\frontend\base\default\layout\layoutname.xml:

<?xml version="1.0"?>
<layout version="0.1.0">
    <layout_handler translate="label">
        <update handle="customer_account_login"/>
    </handler>
</layout>

This is not best solution for me because I did not want to use .xml file.

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.