D
D
Dilik Pulatov2017-06-15 21:28:21
Yii
Dilik Pulatov, 2017-06-15 21:28:21

Problem in Yii2 Yii::$app->runAction()?

Hello!
I have such a problem
, let's say there are such variables in the main controller and it is always available (exactly in the form)

public function beforeAction($action){
  $this->view->code = 'codeblabla';
  return parent::beforeAction($action);
}

everything works correctly as I want.....but when I used runAction() it doesn't work
why? or something I missed? (view variables are not available when using runAction())
+ another question
if I have a file with an array (for example svg.php)
how can I get it in the controller and in the view?
can be used like this
$this->view->svg = include_once("../components/svg.php");

or is there another option?
I would use it with an include and everything worked, but when using runAction() it doesn't work
public function beforeAction($action){
  $this->view->svg = include_once("../components/svg.php");
  return parent::beforeAction($action);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-06-16
@webinar

Why set it in beforeAction, this is the same variable jerking with each request, and the result does not depend on the request. This is weird. Create a public variable in the controller:
In the form:
Or even Yii::$app->params['someName']put in an array

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question