I would like to store data, eg. user name and surname to display them in many layouts. I want to set some variable in one controller and use it in layout.
Any solutions?
I created some similar layouts where i put:
<span id="STATUS">LOGGED: <span id="USERNAME"><?php echo $this->name. ' ' . $this->surname; ?></span>
But firstly, in some action of controller I get name and surname from database:
$db = $this->getServiceLocator()->get('MyDatabase');
$sql = 'SELECT * FROM Users';
$statement = $db->query($sql);/
$result = $statement->execute();
Then i set static variables in controller:
self::$name = $result['name'];
self::$surname = $result['surname'];
Next in actions i change layout and pass variables to it:
$this->layout('layout/student');
$this->layout()->name = self::$name;
$this->layout()->surname = self::$surname;
But I do not want get data from database in every controllers and pass variables in each of actions.
$this->layout('layout/mylayout);
– Łukasz