Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

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

$
0
0
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.

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>