I use one main template and there is another subpattern (I call it so). For example, when I have a page like

http://site.ru/main/profile 

then I additionally load the profile.php template, which is a sublab of main.php.

I need to write a method that will always be called, even if the page looks like

 http://site.ru/main/profile/edit 

I have a ProfileController controller. When the first link - the action is called actionIndex, when the second - actionEdit.

What method should I write, what would it be called in both cases?

  • I did not understand what should be called in both cases. controller, action controller or subpattern profile - Alexey Shimansky
  • I need some kind of action of the ProfileController controller to be performed whenever this controller is involved - Diefair

1 answer 1

In order to perform something before or after the action, yii \ base \ Controller has two methods, beforeAction () - it is executed before any action, and afterAction () - it is executed after any action

 namespace app\controllers; use yii\base\Controller; class ProfileController extends Controller { public function beforeAction($action) { //... return parent::beforeAction($action); } public function afterAction($action, $result) { //.. return parent::afterAction($action, $result); } }