1

I'm getting a

"Fatal error: Call to a member function setTitle() on a non-object in /home/www/public_html/app/code/core/Mage/Customer/Block/Form/Login.php on line 40"

The particular line contains:

 $this->getLayout()->getBlock('head')->setTitle(Mage::helper('customer')->__('Customer Login'));

If I comment out the line the issue is gone - but that is very dissatisfying of course. Since this is a core file it seems something else is causing the issue.

What is the best approach to debug this - or in general a "Call to a member function foo() on a non-object"?

Thank you!

2
  • have you customize customer block file?
    – Abdul
    Nov 24, 2015 at 6:42
  • head block is missing in your loaded layout Nov 24, 2015 at 8:00

2 Answers 2

1

as you already done, the starting point is the line mentioned in the error.
The method setTitle is called from the result of the call ->getBlock('head').
This means that ->getBlock('head') returns something else than an object.
Then check what getBlock should return.
This returns an instance of a block if that one exists in the layout or false if the block does not exist.
This means that the block does not exist in your case.
This can happen for 3 reasons.
The block was never declared in the layout, but this never happens because it is declared in the page.xml file (unless you removed it from there, but I doubt that).
The block was removed via a directive remove through the layout. (possible, but not that probable).
You most probably are using that block before the head block is loaded.
I would look for other occurrences of this block in the layout file and see why it is loaded before the head block.

Side note a bit unrelated: The way this is implemented in the core is wrong. Blocks should not change the title of the page. That should be done in the controller or in the layout files.
Because of this, you are not able to use the same login block to add a small sidebar login on every page, because this way, the title of the page is going to be "Login" on every page.

0

I had this error as well. It was because I was calling getLayout() in my IndexAction() before I had loaded the layout. Just call loadLayout() first, like so:

public function IndexAction() {
  $this->loadLayout(); // do this first
  $this->getLayout()->getBlock('head')->setTitle($this->__('My Title')); // then this works
  $this->renderLayout(); // render as usual
}

I hope this helps

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.