Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7843643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:36:47+00:00 2026-06-02T16:36:47+00:00

I am working my way through a Yii tutorial book and am currently learning

  • 0

I am working my way through a Yii tutorial book and am currently learning about filters. Filters can be applied in general for the controller or just to specific actions.

The example I am working on is creating a new Issue. Each Issue belongs to a single Project, so we add a filter to ensure the project_id is passed to the issue/create page. Since the issue/create is the only page that needs the project_id, we are applying the filter to a single 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 a filter only applies to a single action in the controller, why not just put the filterProjectContext() code directly into the actionCreate() function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:36:49+00:00Added an answer on June 2, 2026 at 4:36 pm

    According the yii docs, and my experience with other frameworks, filters are not meant to be coupled with actions. Rather, filters allow you the ability to access PHP globals such as $_REQUEST values before they reach any actions. For example, I worked on a project where we wanted to highlight all translated text if a url parameter was passed with a specific value. We could have done this in the controller but felt it was better to implement the business rule within a filter. The filter ended up looking like:

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

    The beauty of the filter is that this code would be executed regardless of which action was requested. My suggestion is that you don’t co-mingle filter logic with action logic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been learning Objective-C and Cocoa by working my way through the Hillegass book
I'm currently working my way through Accelerated C++ and just came across this in
I'm currently working my way through the learning curve that is LINQ and I
Working my way through Learn Python the Hard Way ex.25, and I just can't
I'm currently working my way through this book: http://www1.idc.ac.il/tecs/ I'm currently on a section
I've been working my way through the NerdDinner MVC tutorial , and I just
I'm currently working my way through the book Teach Yourself Android Application Development in
I am currently working my way through the Apress ASP.NET MVC2 book, and I
I'm working my way through the Rails Tutorial book by Hartl and I'm completely
I'm working my way through this tutorial here about progress dialogues but have hit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.