Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthortom
     

    Hi,

    I'm trying to run certain default filters defined in my application_controller and then add special filters in subcontrollers as needed. Right now, I've set it up like this:

    class ApplicationController extends AkActionController 
    {
        var $models = "customer";
    
        function __construct() 
        {
            $this->beforeFilter( 'app_setup' );
            $this->afterFilter( 'app_cleanup' );
        }
    
        function app_setup( & $controller ) 
        {
            $_SESSION['customer'] = $controller->Customer->find($_SESSION['customer_id']);
        }
    
        function app_cleanup()
        {
            $_SESSION['customer'] = null;
        }
    
        function login_required() {...}
    }
    

    Then in my other controllers that are derived from ApplicationController:

    class XyzController extends ApplicationController 
    {
        var $models = "customer";
    
        function __construct() 
        {
            $this->beforeFilter( 'login_required' );
        }
    }
    

    Like this, the app_setup seems to get called before handling Requests to Xyz. The problem is that when I run actions in XyzController that access the customer in the session, I get an error saying that the customer object was 'incomplete':

    Isn't it enough to include 'customer' to the $models variable in this case?

    Regards, Tom

    • CommentAuthorKaste
     
    on appController constructor
    $this->beforeFilter('_setsomething');
    function _setsomething(){
    // usually you import a model here (think: require_once)
    Ak::import('A_Model');
    $this->my_model =& new A_Model();
    //dadadum..
    }

    in xyz_controller
    you actually have to call the parent constructor.
    (Ive seen "var $models=xyz" but maybe that gets overridden on a specific controller later)
    • CommentAuthortom
     

    Aha, ok. Seems my filters get called when I arrange it like that (i.e. calling the parent constructor in xyz_controller, adding filters to the chains in both application or xyz controller).

    There seems to be a problem with the $_SESSION, however. Objects I put there in my before filter are not available thereafter...

    • CommentAuthortom
     

    Ok, I got something.

    In my after filter ('app_cleanup'), I remove some bulky objects from $_SESSION so they don't need to get serialized/unserialized at every request. As a result, however, they are unavailable during my action. Seems like the $_SESSION['customer'] = null in app_cleanup() is executed before the action is completely rendered...?!

    Aren't after filters supposed to run after the action rendering is completed??

    regards,
    Tom

    • CommentAuthorKaste
     

    They do.

    Try a test:

    in appContr:

    • var $TestFilters=array();

    in any filter/action you like to test:

    • $this->TestFilters[] = 'im inside xyz';

    in your view:

    {loop TestFilters} <p>{TestFilter}</p> {end}

    • CommentAuthortom
     

    That works, no problem.

    But when I write

    $this->TestFilters = null;

    in my afterFilter, TestFilters[] would be empty during view rendering.

    • CommentAuthorKaste
     

    expected, filters are around actions.

    "afterView" is right before the destructors ;-)