C
C
C_oO_re2014-12-01 11:23:15
Yii
C_oO_re, 2014-12-01 11:23:15

Is it possible to set default filters for all controllers?

I have a redirect filter (previously it was just a helper and was executed in beforeAction in the Controller from which all controllers were extended), but I ran into a problem that filters are executed before beforeAction, and the filter still looks more beautiful than the behaver. So the question arose of what to do really beautifully and completely forget about these SEO things and make this filter the default, are there any options?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nicholas, 2014-12-05
@C_oO_re

What's stopping you from doing filters() in the parent controller?

D
Dmitry Vapelnik, 2014-12-11
@dvapelnik

We take the parent controller:

public function filters()
{
  return array(
      'ie',
      'language',
      'banned',
      'eraserecovery',
      'empty',
      'clearban',
      'jsCookie',
      'css',
      'spoiler',
  );
}

all other controllers inherit from it and write the filters method as follows:
public function filters()
{
  $newFilters = array('access',);

  return array_merge(parent::filters(), $newFilters);
}

i.e., in the extended method, we merge our filters with the filters of the parent class
// this highlighter code somehow obliquely displays, but the essence, I think, is clear

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question