Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $controller = isset($_GET['controller']) ? $_GET['controller'] : 'digests';
- $action = isset($_GET['action4']) ? $_GET['action4'] : 'view_page';
- $injector = init();
- $output4 = dispatch($controller, $action, $injector);
- echo $output4;
- //----------------------------------------------
- // autoload
- //----------------------------------------------
- function __autoload($className) {
- $DS = DIRECTORY_SEPARATOR;
- $ROOT = dirname(__FILE__);
- require ($ROOT.$DS.'classmap.php');
- $zclass=$className;
- foreach (Array('Form','View','Controller') as $el) {
- if (strpos($className, $el)!==false) {
- $zclass = substr($className,0, strpos($className, $el));
- $zclass =rtrim($zclass,'s');
- break;
- }
- }
- $app_f = $ROOT. $DS. 'app'.$DS. strtolower($zclass).'.inc.php';
- $base_f = $ROOT. $DS. 'base.inc.php';
- if (file_exists($app_f)) {
- require_once($app_f);
- }
- else if (isset($classmap[$className]) && file_exists($ROOT.$DS.$classmap[$className])) {
- require_once ($ROOT.$DS.$classmap[$className]);
- }
- else
- require_once($base_f);
- }
- //----------------------------------------------
- // initialization
- //----------------------------------------------
- function init() {
- $injector = new Injector();
- $debug = new Debugger();
- $debug->debugMode(1);
- $dbconn = new DBConn();
- $dbconn->set('','','','');
- $dbconn->connect();
- $injector->set($dbconn);
- $injector->set($debug);
- return $injector;
- }
- //----------------------------------------------
- // dispatch
- //----------------------------------------------
- function dispatch($controller, $action, $injector) {
- $controllerName = $controller;
- $controller = ucwords($controller);
- //-----------------------
- $dbmodel = new DBModel($injector);
- $injector->set($dbmodel);
- //-------------------------
- $modelName = rtrim($controller,'s');
- $model = new $modelName($injector);
- $injector->set($model);
- //--------------------
- $decorator = new Decorator($injector);
- $injector->set($decorator);
- $formName = $controller.'Form';
- $form = new $formName($injector);
- $injector->set($form);
- //--------------------
- $viewName = $controller.'View';
- $view = new $viewName($injector);
- $injector->set($view);
- //-----------------------------
- $controller .= 'Controller';
- $dispatch = new $controller($injector, $controllerName, $action);
- $dispatch->dispatch();
- $output = $dispatch->render(false);
- return $output;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement