php";
if (file_exists($controllerfile)){
require_once($controllerfile);
$app = new $controller();
$app->use_layout = true;
$app->setParams($params);
$app->$action();
unittest::tearDown();
ob_end_clean();
//manage view
ob_start();
$view = loader::load("view");
$viewvars = $view->getVars($app);
$uselayout = $config->use_layout;
if (!$app->use_layout) $uselayout=false;
$template = $view->getTemplate($action);
base::_loadTemplate($controller, $template,
$viewvars, $uselayout);
if (isset($start))
echo "
Total time for dispatching is :
".(microtime(true)-$start)." seconds.
";
$output = ob_get_clean();
//$cache->set("abcde",array
("content"=>base64_encode($output)));
echo $output;
}
else
throw new Exception("Controller not found");
}
}
?>
Here's what dispatcher mainly does (as seen from the highlighted section of the
above code). It takes a router object as parameter then finds controller, action, and
parameters from router. If the controller file is available, it loads that and then
initializes the controller. After initializing, it just accesses the action.
Chapter 9
[ 219 ]
After that, dispatcher initializes the current view object using loader.
Pages:
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233