A
A
Andrew2015-06-07 00:03:25
Yii
Andrew, 2015-06-07 00:03:25

Creating a block site and passing a variable to layout?

I ask for help in what, in my index.php one view is rendered and it works like normal. rendered in content/
<?php $this->renderPartial('_topicday', array('topicday' => $topicday)); ?>
Now we need to make a new layout and drive this block into haeder where the logo is. One of the ideas is to insert this block into the layout, but here's the problem - an error is thrown - "undefined variable topicday "/ How to solve this problem, can anyone advise. I understand the question is amateurish but I'm not catching up on how to do it. Either the first option or the second.
and also the second question:
I want to make a site with 3 columns, but I want columns 1 and 3 not to change. Who will advise? There is an option to make panels, but there is a portlet. Looking for advice, thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Belikov, 2015-06-07
@asder117

Here are a couple of ways:

  • arrange as a widget
  • declare a variable in the controller and output it in the view
// В контроллере
public $topicday = "defaultvalue";;
public function actionTest() {
  $this->topicday = "somevalue";
  // ...
}
// Вывод в представлении (layout)
<?= $this->topicday ?>

PS
If you need to use the second method, then you need to do this in the view:
Just keep in mind that this property needs to be set to some default value or to be checked in _topicday itself, and if it is NULL, then output nothing because your layout may be used by other controllers and the value of the public property $topicdaymay not be defined in them.
In general, this case completely fits the category - a widget, there is nothing difficult in their implementation, and after you do it, you will understand how beautiful this solution is and how convenient it is. The guide can be viewed here www.bsourcecode.com/yiiframework2/how-to-create-cu... In the code it will
be displayed something like this:
something to depend on.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question