Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Example of using JadedPHP controllers, filters and filter chains.
<?php
// initialize the JadedPHP library here
class MyController extends Jaded_Controller
{
protected function process(Jaded_Request $oRequest, Jaded_Response $oResponse)
{
$oResponse->assign('myVar', 'this is the assigned value');
$oResponse->assign('requestVar', $oRequest->getParam('reqParam'));
}
}
class RequestFillerFilter extends Jaded_Controller_Filter_PreProcessor
{
protected function preProcess(Jaded_Request $oRequest, Jaded_Response $oResponse)
{
$oRequest->setParam('requestVar', 123);
}
}
class Print_RFilter extends Jaded_Controller_Filter_PostProcessor
{
protected function postProcess(Jaded_Request $oRequest, Jaded_Response $oResponse)
{
print_r($oResponse->getAssigns());
}
}
class CommonFilterChain extends Jaded_Controller_Filter_Chain
{
protected $aFilters = array(
'Print_RFilter',
'RequestFillerFilter',
);
}
$oController = new MyController();
$oRequest = new Jaded_Request();
$oResponse = new Jaded_Response();
$oFilter = new CommonFilterChain($oController);
$oFilter->dispatch($oRequest, $oResponse);
/*
Prints:
Array
(
[myVar] => 'this is the assigned value'
[requestVar] => 123
)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment