0

I am working on custom module.The code is written in following order:

class JG_Mymodule_Model_Mysql4_Mymodule{ }

One of my friend wirte code in model like that:

protected function _afterLoad(Mage_Core_Model_Abstract $object)
    {


        $select = $this->_getReadAdapter()->select()
            ->from($this->getTable('findyoursize_values'))
            ->where('findyoursize_id = ?', $object->getId());

        if ($data = $this->_getReadAdapter()->fetchAll($select)) {
            $storesArray = array();
            foreach ($data as $row) {
                $storesArray[] = $row['dimensions_id'];
            }
           $object->setData('in_products', $storesArray);
            Mage::getSingleton('core/session')->setMyValue($storesArray);
        }

        return parent::_afterLoad($object);

    }.

I want to use $object->setData('in_products') value in my block class , how can I access that value?

2

I'm not sure why you are copying (not referencing) the in_products property to the session instance, given that it's available on the object instance which you are load()ing.

I recommend to always pull this array from the model instance. $object->getInProducts() and $object->getData('in_products') are both acceptable.

| improve this answer | |
  • I didn't get you point clearly.because this object can't be accessible in block class . is it ?.If you see at my question i use session for that but it is alternate way.I want to do it without session.Hope you got my point – Mahmood Rehman Jul 16 '13 at 4:11
  • In your block's _prepareLayout() method you can instantiate your model using e.g. $model = Mage::getModel(/* class */), call load(/* id */) as you must currently be doing, and then assign the model instance to the block instance scope using $this->setModel($model). You can then retrieve the model instance in the block or in the template using $this->getModel(). – benmarks Jul 16 '13 at 12:46
  • Thanks i got my value like this $vari = Mage::getModel('findyoursize/findyoursize')->load($this->getRequest()->getParam('id')); print_r($vari->getData('in_products'));.I want to chat with you for one other little issue.i have also posted question for that.you can see it on link.[magento.stackexchange.com/questions/5795/… – Mahmood Rehman Jul 17 '13 at 7:02

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.