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
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...
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
They do.
Try a test:
in appContr:
in any filter/action you like to test:
in your view:
{loop TestFilters} <p>{TestFilter}</p> {end}
That works, no problem.
But when I write
$this->TestFilters = null;
in my afterFilter, TestFilters[] would be empty during view rendering.
expected, filters are around actions.
"afterView" is right before the destructors ;-)
1 to 7 of 7