Y
Y
yeezussniper2021-02-21 12:06:50
Yii
yeezussniper, 2021-02-21 12:06:50

How to pass object from controller to head?

Greetings. Help me deal with one issue: you need to pass an object with data from sql to views -> layouts -> main.php (where the head is located). Usually in the controller I take data from the database and pass it to views via return $this->render(). I also need to take the data from the database (a list of cities in a normal sql table) and pass the object with the data to (which is wrapped by $this->beginPage())

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
coderisimo, 2021-02-21
@yeezussniper

We look in the dock

// в контроллере
$this->view->params['customParam'] = 'hello Yii!';

// в представлении, включая главный лэйаут
echo $this->params['customParam'];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question