2
class Mymodule_Product_Block_Adminhtml_Product extends Mage_Adminhtml_Block_Widget_Grid_Container {

    public function __construct() {
        $this->_controller = "adminhtml_product";
        $this->_blockGroup = "product";
        $this->_headerText = Mage::helper("product")->__("Product Manager");
        $this->_addButtonLabel = Mage::helper("product")->__("Add New Product");
        $form_key = 123;
        Mage::getSingleton('core/session')->setFormKeyCustom($form_key);
        $this->_addButton('import', array(
            'label' => Mage::helper('product')->__('Import'),
            'onclick' => "uploadDoc('" . $this->getBaseUrl() . "product/csvupload/index/key/" . $form_key . "');",
            'class' => 'add',
            'after_html' => '',
        ));
        parent::__construct();
    }

}

Why I am not able to get that session in a frontcontroller action ?? I am getting blank Mage::getSingleton('core/session')->getFormKeyCustom();

1 Answer 1

3

You are not able to use the customer/session or core/session inside the construct of the any controller because the preDispatch method of Mage_Core_Controller_Varien_Action starts the session. The line that do that is the following

$session = Mage::getSingleton('core/session', array('name' => $this->_sessionNamespace))->start();

So, as the core/session is a singleton object if you call any method of the session object, you get a empty session forever.

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.