0

I have a module in which a protected variable is defined as follows:

protected $stores = array('a','b', 'c', 'd');

I want to load define this variable inside a custom block so I am trying to do this:

protected $staticBlock = Mage::getModel('cms/block')->load('custom_block')->getContent();

protected $stores = array($staticBlock);

This gives me PHP errors of course.

It really sounds like a newling question, but the real problem is that I tried to transform it into a function, but the entire code uses the variable without calling anything except the variable directly. I am really lost now and can't find a way to achieve this.

Any idea will be appreciated.

Thanks

Gabriel G
  • 33
  • 1
  • 8

1 Answers1

0

If I have understood what you want... why not just this?

protected $staticBlock = null;

And then, before using $this->staticBlock property (in class constructor, for instance, if that fits your needings)

$this->staticBlock = Mage::getModel('cms/block')->load('custom_block')->getContent();

About $this->stores property, I am not totally sure what you are asking for, or if that's just an example

UPDATE

If you want to avoid calling multiple times that code you can use a helper class, which is always instantiated as singleton https://magento.stackexchange.com/a/74991/3566, something like this

protected $staticBlock = null;

public function getStaticBlock()
{
    if (is_null($this->staticBlock)){
        $this->staticBlock = Mage::getModel('cms/block')->load('custom_block')->getContent();
    }
    return $this->staticBlock;
}
Raul Sanchez
  • 3,036
  • 3
  • 28
  • 63