Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot Access Methods of $this-object #10

Closed
ghost opened this issue Jul 9, 2015 · 3 comments
Closed

Cannot Access Methods of $this-object #10

ghost opened this issue Jul 9, 2015 · 3 comments

Comments

@ghost
Copy link

ghost commented Jul 9, 2015

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.

Problem

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.

Question

How can I call a method from an object which is given to smarty from PHP ?

  1. Define variable for use in smarty: $template->assign('app', \Yii::$app);
  2. Call method on variable in smarty template: {$app->getSession();}

What am I doing wrong ?
(my current smarty layout: pastebin)

If this is no issue to Yii2-Smarty

I'm sorry if this doesn't affect Yii2-Smarty at all but I cant figure out what/why it is not working since this code should work according to Yii2-Smarty and Smarty itself.

I've also asked this question on stackoverflow though nobody has yet answered.

@cebe
Copy link
Member

cebe commented Jul 9, 2015

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: http://www.yiiframework.com/doc-2.0/yii-web-view.html#head%28%29-detail

You can call the method like this:

{$this->head()}

@cebe cebe closed this as completed Jul 9, 2015
@ghost
Copy link
Author

ghost commented Jul 9, 2015

Okey, but then how do I include the assets from my project in the layout/main.tpl ?
Thought it were done through the yii\web\View::head() method but now I can't find it.

@cebe
Copy link
Member

cebe commented Jul 9, 2015

the head method does that, but it does not return them, it sets a marker that is later replaced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant