Return True/false From Cfilter And Get That Value In Another Filter

Hey Guys,

I’ve set up an rest API that is super predictable.

/x

/x/y

/x/y/z

/x/y/z/&

X can be any controller, Y any ID, Z any action, and & any $id2

Because of this predictable nature, and my desire to log every action and it’s consequence I’ve got the following example.





<?php


class LoggingFilter extends CFilter{

    

    private $_state;

    

    protected function preFilter($filterChain){

        $this->_state = 'ATTEMPTING TO ACCESS';

        

        return true; // false if the action should not be executed

    }

 

    protected function postFilter($filterChain){

        

        $this->_state = 'ATTEMPTING TO ACCESS FAILED';

        // LOG SUCCESS / FAILURE BASED ON ACCESSFILTER AND OTHER FILTERS

    }

}


<?php


class ApiFilter extends CFilter{

    protected function preFilter($filterChain){

        return false; // false if the action should not be executed

    }

 

    protected function postFilter($filterChain){

    }

}


// Defined in components/Controller

public function filters(){

    return array(

	array(

	    'application.filters.LoggingFilter',

	),

	array(

	    'application.filters.ApiFilter',

	),

    );

}



My postFilter for logging executes even if I return false from the api filter. PERFECT. But how do I know the API filter return false and that execution should end?

Idea: I basically want to log the following in pseudo

"User $x attempted to access resource $y and was denied/allowed";

Thanks guys. I’ve been looking at the docs and haven’t gotten anywhere I want to yet.

Hey Guys,

If anyone else is looking to do this, You can try using the following to get the error context if it is available. I just check this and if it is set, I save the response code.





if(:$error=Yii::app()->errorHandler->error){

}



Thank you for your time if you had looked and not found anything. The answer was in the blog demo site/error - can’t believe I didn’t think to look there! I thought it might have a function($x,$y) signature but no! It is awesome.