Advertisement
terorama

mvcnew / ajax_ind.php

Apr 30th, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.94 KB | None | 0 0
  1. <?php
  2.  
  3.   session_start();
  4.  
  5.   $controller = isset($_GET['controller']) ? $_GET['controller'] : 'digests';
  6.   $action = isset($_GET['action4']) ?  $_GET['action4'] : 'view_page';
  7.  
  8.   $injector = init();
  9.  
  10.   $output4 = dispatch($controller, $action, $injector);
  11.  
  12.   echo $output4;
  13.  
  14.  
  15.   //----------------------------------------------
  16. //             autoload
  17. //----------------------------------------------
  18. function __autoload($className) {
  19.    
  20.    $DS = DIRECTORY_SEPARATOR;
  21.    $ROOT =  dirname(__FILE__);
  22.    
  23.    require ($ROOT.$DS.'classmap.php');
  24.    
  25.    $zclass=$className;
  26.    foreach (Array('Form','View','Controller') as $el) {
  27.       if (strpos($className, $el)!==false) {
  28.          $zclass = substr($className,0, strpos($className, $el));
  29.          $zclass =rtrim($zclass,'s');
  30.          break;
  31.          
  32.          }
  33.    }
  34.    
  35.    $app_f = $ROOT. $DS. 'app'.$DS. strtolower($zclass).'.inc.php';
  36.  
  37.    $base_f = $ROOT. $DS. 'base.inc.php';
  38.    
  39.    if (file_exists($app_f)) {
  40.    
  41.       require_once($app_f);
  42.           }
  43.    else if (isset($classmap[$className]) && file_exists($ROOT.$DS.$classmap[$className])) {
  44.      
  45.       require_once ($ROOT.$DS.$classmap[$className]);
  46.    }
  47.    else
  48.       require_once($base_f);    
  49. }
  50.  
  51.  
  52. //----------------------------------------------
  53. //          initialization
  54. //----------------------------------------------
  55. function init() {
  56.    
  57.    $injector = new Injector();
  58.    
  59.    $debug = new Debugger();
  60.    $debug->debugMode(1);
  61.  
  62.    $dbconn = new DBConn();
  63.    $dbconn->set('','','','');
  64.    $dbconn->connect();
  65.  
  66.  
  67.    $injector->set($dbconn);
  68.    $injector->set($debug);
  69.    
  70.    return $injector;
  71.    
  72.  
  73. }
  74.  
  75. //----------------------------------------------
  76. //                dispatch
  77. //----------------------------------------------
  78. function dispatch($controller, $action, $injector) {
  79.  
  80.    $controllerName = $controller;
  81.    $controller = ucwords($controller);
  82.    
  83.    //-----------------------
  84.    $dbmodel = new DBModel($injector);
  85.    $injector->set($dbmodel);
  86.  
  87.         //-------------------------
  88.         $modelName = rtrim($controller,'s');  
  89.         $model = new $modelName($injector);
  90.         $injector->set($model);
  91.        
  92.              //--------------------
  93.             $decorator = new Decorator($injector);
  94.             $injector->set($decorator);
  95.    
  96.             $formName = $controller.'Form';
  97.             $form = new $formName($injector);
  98.             $injector->set($form);
  99.            
  100.                    //--------------------
  101.                    $viewName = $controller.'View';
  102.                    $view = new $viewName($injector);
  103.                    $injector->set($view);
  104.    
  105.                             //-----------------------------
  106.                             $controller .= 'Controller';
  107.                             $dispatch  = new $controller($injector, $controllerName, $action);  
  108.                            
  109.    $dispatch->dispatch();
  110.    $output = $dispatch->render(false);
  111.    
  112.    return $output;
  113. }
  114.  
  115.  
  116.  
  117. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement