Yii - What is the use of a filter if it is intended for only one action?

I am working on a Yii tutorial and am currently studying filters. Filters can be used generally for the controller or only for specific actions.

In the example that I am working, a new problem is created. Each problem relates to one project, so we add a filter to pass project_idto the page issue/create. Since this issue/createis the only page that needs project_id, we apply a filter to one action:

public function filters(){
    return array(
        'accessControl', // perform access control for CRUD operations
            'projectContext + create',//check to ensure valid project context
    );
}

My question is this: if the filter is applied to only one action in the controller, why not just put the code filterProjectContext()directly into the function actionCreate()?

+3
source share
1 answer

yii docs, , . , PHP, $_REQUEST, - . , , , url . , , - . :

// Symfony code, but should demonstrate the idea
if ($context->getRequest()->getParameter('highlightTranslations') === 'y') {
    // Tell translator API to highlight any subsequent translations
}

, , . , .

+5

All Articles