Hello!

I want to automatically transfer to the main, relative to the current context.

I use this code in the header on the view.

$this->registerMetaTag([ 'name' => 'meta', 'http-equiv' => 'refresh', 'content' => "5; $this->context->module->homeUrl", ]); 

Throws an error with this code ($ this-> context-> module-> homeUrl)

 An Error occurred while handling another error: yii\base\ErrorException: Object of class app\...\DefaultController could not be converted to string in C:\....\error.php:15 Stack trace: 

But when calling this code ($ this-> context-> module-> homeUrl) via var_dump, the string string (7) / admin / is output

What could be the problem? Meta tags do not display a string, but in other places of norms, like a string.

  • 'content' => "5; $this->context->module->homeUrl", this is the 15th line with an error in the file C:\....\error.php - Nikolaj Sarry
  • Yes, it is, but why does it not take it as a string? if it is a string) If you display the same code in the view below, somewhere, then everything is fine. Or throw in Html :: a (), the link will also work. - ratatuy
  • I could of course pass through the controller, but it makes sense if I use this page as a settler (404), and I don’t use actions. - ratatuy

1 answer 1

 $this->registerMetaTag([ 'name' => 'meta', 'http-equiv' => 'refresh', 'content' => "5;{$this->context->module->homeUrl}", ]); 

Added {} and solved the problem.