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

coder
  • 713
  • 3
  • 13
  • 26

1 Answers1

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()

Marius
  • 197,939
  • 53
  • 422
  • 830