Component helper methods to set variables
3
Creating helper class that we can use to extend other components.
BaseComponent.php
use Cms\Classes\ComponentBase;
abstract class BaseComponent extends ComponentBase
{
protected function setVar($name, $value)
{
return $this->$name = $this->page[$name] = $value;
}
protected function setPageVar($name, $value)
{
return $this->page[$name] = $value;
}
}
Usage of methods:
setVar
- if we want to set component variable and page variablesetPageVar
- or if we want to set only page variable
Then we can extend one of our Components like this.
class ProductsList extends BaseComponent
{
public $myVariable;
public function init()
{
$this->setVar('myVariable', 'value');
$this->setPageVar('myPageVariable', 'value2');
}
}
There are no comments yet
Be the first one to comment