I set up Yii2 with smarty extension.
Now I am trying to simply convert the layouts/main.php
file to a smarty template. For that I need access to the current yii\web\View
object which is given from the extension as $this
-smarty-variable.
I've validated that the smarty $this
variable was the same as the view-object through var_dump()
-ing and comparing both.
According to the smarty3 docs I should be able to call a method on the $this
-object from smarty templates like this: {var_dump($this->head())}
.
Applying the above script in a template just always returns NULL
which let me guess that no method call had happen.
How can I call a method from an object which is given to smarty from PHP ?
$template->assign('app', \Yii::$app);
{$app->getSession();}
What am I doing wrong ?
(my current smarty layout: pastebin)
Applying the above script in a template just always returns NULL which let me guess that no method call had happen.
the head() method does not return anything so if you see null that is correct.
You can call the method like this:
{$this->head()}