3
  public function _construct(){

     $this->loadLayout();
    $this->renderLayout();

}

public function indexAction(){

    $this->loadLayout();
    $this->renderLayout();

    echo "see My Controller";
}

When I am call layout in index controller the it will display the my cuttent theme. and when I call in _construct then it's display magento default theme. why? can you explain ? how to set my current theme in _construct() function magento extension

  • Try to add this line Mage::app()->loadArea($this->getLayout()->getArea()); before loadLayout – Marius Aug 28 '14 at 7:55
  • I will add it as an answer. I added it as a comment because it was a shot in the dark. :) – Marius Aug 28 '14 at 8:00
4

You need to add

Mage::app()->loadArea($this->getLayout()->getArea());

in your constructor before loading the layout.
That line is needed so magento will know what area to load.
It works in an action because the action is called after preDispatch() is called, and that's where the area is usually loaded.

It doesn't work in the constructor by default because the constructor is called prior to calling preDispatch()

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.