Advertisement
terorama

mvc / index.php

Dec 22nd, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.66 KB | None | 0 0
  1. <?php
  2.  
  3. //----------------------------------------------
  4. //               BootStrap
  5. //----------------------------------------------
  6.  
  7. define ('DS',DIRECTORY_SEPARATOR);
  8. define ('ROOT', dirname(__FILE__));
  9. define ('DEBUG_MODE', true);
  10.  
  11. session_start();
  12.  
  13. Debugger::prepare();
  14.  
  15.    $controller = isset($_GET['controller']) ? $_GET['controller'] : 'questions';
  16.    $action = isset($_GET['action']) ?  $_GET['action'] : 'view_page';
  17.  
  18. init();
  19.  
  20. $output4 = dispatch($controller, $action);
  21.  
  22. //----------------------------------------------
  23. //             autoload
  24. //----------------------------------------------
  25. function __autoload($className) {
  26.    
  27.    $controller_f = ROOT. DS. 'app'.DS.'controllers'.DS. strtolower($className).'.inc.php';
  28.    $model_f =      ROOT. DS. 'app'.DS.'models'.DS. strtolower($className).'.inc.php';
  29.    $view_f =       ROOT. DS. 'app'.DS.'views'.DS. strtolower($className).'.inc.php';
  30.    
  31.    $base_f = ROOT. DS. 'library'.DS. 'base.inc.php';
  32.    
  33.    if (file_exists($controller_f)) {
  34.    
  35.       require_once($controller_f);
  36.       }
  37.    else if (file_exists($model_f)) {
  38.      
  39.       require_once($model_f);
  40.       }
  41.    else if (file_exists($view_f)) {
  42.      
  43.       require_once($view_f);
  44.    }
  45.    else
  46.       require_once($base_f);     
  47. }
  48.  
  49.  
  50. //----------------------------------------------
  51. //          initialization
  52. //----------------------------------------------
  53. function init() {
  54.  
  55.    define('DB_HOST','localhost');
  56.    define('DB_NAME','');
  57.    define('DB_USER','');
  58.    define('DB_PASSWORD','');
  59.  
  60.    DBConn::set(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
  61. }
  62.  
  63. //----------------------------------------------
  64. //                dispatch
  65. //----------------------------------------------
  66. function dispatch($controller, $action) {
  67.  
  68.  
  69.    $controllerName = $controller;
  70.    $controller = ucwords($controller);
  71.    $model = rtrim($controller,'s');
  72.    $view = $controller.'View';
  73.    $controller .= 'Controller';
  74.  
  75.    $dispatch  = new $controller($model, $view, $controllerName, $action);  
  76.    $dispatch->dispatch();
  77.    
  78.    $output = $dispatch->render(false);
  79.    
  80.    $related = $dispatch->related();
  81.    
  82.    //----------------------------
  83.    foreach ($related as $controller_related) {
  84.      
  85.       $output .=  dispatch($controller_related, $action);
  86.    }
  87.    
  88.    return $output;
  89. }
  90.  
  91. ?>
  92.  
  93. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  94. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  95. <head>
  96.    <title>mvc - example</title>
  97.    
  98.    <style type="text/css">
  99.       * {
  100.          margin: 0;
  101.          padding: 0;
  102.          border: none;
  103.          outline: none;
  104.          
  105.       }
  106.      
  107.       body {
  108.          font-family: verdana, sans-serif;
  109.          font-size:100%;
  110.       }
  111.      
  112.       #container {
  113.      
  114.          width:1000px;
  115.          margin:0 auto;
  116.       }
  117.      
  118.       #questions {
  119.          margin-bottom: 10px;
  120.       }
  121.      
  122.       .header {
  123.          height:100px;
  124.          color:#333;
  125.          font-size:1.5em;
  126.          line-height:1.5em;
  127.          text-align:center;
  128.          letter-spacing:3px;
  129.          
  130.          background: #eee;
  131.          
  132.          border-radius: 100px 60px 50px 10px;
  133.          -moz-border-radius: 100px 60px 50px 10px;
  134.          -webkit-border-radius: 100px 60px 50px 10px;
  135.          
  136.       }
  137.       .content {
  138.          float:left;
  139.          width:800px;
  140.          margin-bottom: 20px;
  141.       }
  142.      
  143.       .page {
  144.       }
  145.      
  146.       .entrytitle {
  147.          margin-top: 10px;
  148.          font-size:1.2em;
  149.          font-weight:bold;
  150.          
  151.          height:30px;
  152.          line-height:30px;
  153.          text-align:center;
  154.          
  155.          background: #aaa;
  156.          
  157.          
  158.          border-radius:10px;
  159.          -moz-border-radius:10px;
  160.          -webkit-border-radius:10px;
  161.       }
  162.       .entrytitle a {
  163.          color:white;
  164.          text-decoration: none;
  165.          
  166.       }
  167.       .entrytitle a:hover {
  168.          color:#3f3;
  169.       }
  170.       .entrycontent {
  171.          padding: 4px 20px 5px 10px;
  172.          border-bottom: solid 1px #999;
  173.          
  174.       }
  175.       .entrycategory {
  176.      
  177.          height:30px;
  178.          background: #eee;
  179.       }
  180.       .entryuser {
  181.          font-family:georgia, serif;
  182.          font-size:0.75em;
  183.       }
  184.       .entrydate {
  185.          font-size:0.75em;
  186.          font-style: italic;
  187.       }
  188.      
  189.       .entryeditpanel {  
  190.          margin-top:10px;
  191.          overflow:hidden;
  192.       }
  193.        .editpanel {
  194.           overflow:hidden;
  195.       }
  196.       .editbutton, .deletebutton, .addbutton, .backtolistbutton {
  197.      
  198.          background:#ff9;
  199.          
  200.          font-weight:bold;
  201.          font-size: 0.75em;
  202.          text-align:center;
  203.          padding:4px 10px;
  204.          margin-right:5px;
  205.          
  206.          border: solid 2px #800;
  207.          -moz-border-radius: 8px;
  208.          -webkit-border-radius: 8px;
  209.          border-radius: 8px;
  210.          
  211.          float:left;
  212.       }
  213.      
  214.       .editbutton a, .deletebutton a, .addbutton a, .backtolistbutton a{
  215.      
  216.          color:#c00;
  217.          text-decoration: none;
  218.       }
  219.       .editbutton {
  220.        
  221.       }
  222.       .deletebutton {
  223.       }
  224.      
  225.       .addbutton {
  226.       }
  227.       .backtolistbutton {
  228.       }  
  229.      
  230.       .sidebar {
  231.          float:right;
  232.          width:190px;
  233.          min-height: 200px;
  234.          margin-top:10px;
  235.          background: #f5f5f5;
  236.       }
  237.      
  238.       .footer {
  239.          clear:both;       
  240.          background: #f0f0f0;
  241.          padding: 10px 20px;
  242.        
  243.          
  244.       }
  245.  
  246.      
  247.       .navigation {
  248.          margin-top:4px;
  249.          overflow: hidden;
  250.       }
  251.      
  252.       .navigation ul {
  253.          list-style-type:none;
  254.       }
  255.       .navigation li {
  256.          float:left;
  257.          margin-right: 5px;
  258.          text-align:center;
  259.          height:40px;
  260.          line-height:40px;
  261.          background: white;
  262.          font-weight: bold;
  263.          width: 40px;
  264.          border: solid 1px #555;
  265.          -moz-border-radius:4px;
  266.          -webkit-border-radius:4px;
  267.       }
  268.       .navigation li a, .navigation li a:visited {
  269.          text-decoration:none;
  270.          color: #800;
  271.       }
  272.       .navigation li a:hover {
  273.          text-decoration: underline;
  274.       }
  275.      
  276.       form {
  277.          
  278.          padding:20px 40px 10px 20px;
  279.       }
  280.      
  281.       fieldset {
  282.          padding-top:10px;
  283.       }
  284.      
  285.       legend {
  286.          border:solid 1px #aaa;
  287.          border-radius:4px;
  288.          -moz-border-radius:4px;
  289.          -webkit-border-radius:4px;
  290.          padding:4px 20px;
  291.       }
  292.       label {
  293.          display:block;
  294.          float:left;
  295.          clear:left;
  296.          width:200px;
  297.          margin-right:10px;
  298.          margin-top: 5px;
  299.       }
  300.       input {
  301.          display: block;
  302.          
  303.          border: solid 1px #aaa;
  304.          border-radius: 4px;
  305.          -moz-border-radius: 4px;
  306.          -webkit-border-radius: 4px;
  307.          padding:2px 5px;
  308.          margin-top:5px;
  309.       }
  310.      
  311.       input[type=text] {
  312.          width:400px;
  313.       }
  314.      
  315.       input[type=submit], input[type=button] {
  316.      
  317.          background:#ffa;
  318.          float:left;
  319.          border:solid 2px #a00;
  320.          border-radius 8px;
  321.          -moz-border-radius 8px;
  322.          -webkit-border-radius 8px;
  323.          color:#b00;
  324.          cursor:pointer;
  325.          padding:4px 20px;
  326.          
  327.          font-size:1em;
  328.          margin-right:10px;
  329.          margin-top:10px;
  330.          
  331.       }
  332.      
  333.      
  334.    </style>
  335. </head>
  336.  
  337.  
  338. <body>
  339.    <div id="container">
  340.       <?php echo $output4; ?>
  341.    </div>
  342.    
  343. </body>
  344.  
  345.  
  346. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement