View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template}

{zone-data:component-name}
Intercepting Filters
{zone-data}

{zone-data:proposer-list}
[Mike Borozdin|mailto:shadow@mikeborozdin.com], author
[Darby Felton|mailto:darby@zend.com], Zend liaison
{zone-data}

{zone-data:revision}
1.1 - 18 July 2006: Some thoughts of mine.
{zone-data}

{zone-data:overview}
Zend Framework lacks of intercepting filters that should be executed before a specified controllers or actions in order to make some validations, for example, check whether user is authenticated if not then redirect to a login page, the code can look something like this
{code}
$controller = Zend_Controller_Front::getInstance();
$filterChain = new Zend_Filter_Chain();
$filterChain->add(new AuthenticationFilter(), "pages", array("add", "edit", "remove"));
$controller->setFilterChain($filterChain);
{code}

For instance, we have PagesController that has four actions: viewAction(), addAction(), editAction(), removeAction(), the last three actions can be performed by autenticates users only, so we must check. Sure, we can put this logic to the action method or write Authenticated_Controller_Action, but what if we have to make some other validations.

Zend Framework has a plugin mechanism that is not documented now, I tried to make a plugin that extends Zend_Controller_Plugin_Abstract but it lacks of interaction with controllers and action, besides it can't stop the routing process.

If you have any ideas, please comment or e-mail me.
{zone-data}

{zone-data:references}
* [Core J2EE Patterns - Intercepting Filter|http://java.sun.com/blueprints/corej2eepatterns/Patterns/InterceptingFilter.html]
* [SitePoint threads|http://www.sitepoint.com/forums/search.php?searchid=2359554]
{zone-data}


{zone-template-instance}]]></ac:plain-text-body></ac:macro>