當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Dispatcher::controller方法代碼示例

本文整理匯總了PHP中Dispatcher::controller方法的典型用法代碼示例。如果您正苦於以下問題:PHP Dispatcher::controller方法的具體用法?PHP Dispatcher::controller怎麽用?PHP Dispatcher::controller使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Dispatcher的用法示例。


在下文中一共展示了Dispatcher::controller方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: run

 public static function run()
 {
     $controllerClassName = self::get('controller') . 'Controller';
     $action = self::get('action') . 'Action';
     self::$controller = new $controllerClassName();
     call_user_func_array(array(self::$controller, $action), array());
 }
開發者ID:Jaleko,項目名稱:php-framework,代碼行數:7,代碼來源:Dispatcher.php

示例2: main

 public static function main()
 {
     require_once 'lib/functions.php';
     session_start();
     header('Content-Type: text/html; charset=UTF-8');
     if (!function_exists('apache_request_headers')) {
         exit('Apache server is required because I\'m too lazy to figure out another way to detect for XHR. (PHP function "apache_requestHeaders" not found)');
     }
     $requestHeaders = apache_request_headers();
     //get headers for AJAX detection
     define('BASEDIR', dirname(__FILE__));
     define('IS_AJAX', !empty($requestHeaders['X-Requested-With']) && $requestHeaders['X-Requested-With'] == 'XMLHttpRequest');
     define('DS', DIRECTORY_SEPARATOR);
     $controller = 'Controller';
     //set default controller if there is 1 or none URL frags
     $action = 'index';
     //set default action (that runs off of default controller) for empty URL
     $actionArguments = array();
     if (!empty($_GET['url'])) {
         $params = explode("/", $_GET['url']);
         //turn URL into an array
         if (count($params) == 1 || $params[1] == '') {
             //both of these check for URLs with one frag
             $action = preg_replace('/[^a-zA-Z0-9-_]/', '', $params[0]);
         } else {
             $controller = ucwords(preg_replace('/[^a-zA-Z0-9-_]/', '', $params[0])) . "Controller";
             $action = preg_replace('/[^a-zA-Z0-9-_]/', '', $params[1]);
             if (count($params) > 2) {
                 $actionArguments = array_slice($params, 2);
                 //get an array of arguments
             }
         }
     }
     $controllerFileName = BASEDIR . DS . "controllers" . DS . "{$controller}.php";
     if (!file_exists($controllerFileName)) {
         exit("Could not find controller file <b>{$controllerFileName}</b>");
     }
     require_once 'controllers/Controller.php';
     require_once $controllerFileName;
     //create internally usable, externally inaccessible public class methods by prefacing the method with an underscore
     //this is the "externally inaccessible" part being implemented:
     if (substr($action, 0, 1) == '_') {
         exit("Failure to load pseudo-protected controller action <b>{$action}</b>.");
     }
     if (!method_exists($controller, $action)) {
         exit("Failure to load Controller action <b>{$action}</b>. Method does not exist.");
     }
     //Whatever string that $controller contains is the name of the class that is created here.
     //The new object is set as Dispatcher's static var $controller, via self::$controller
     self::$controller = new $controller($controller, $action, $actionArguments);
     //calls the Controller's action, passing any URL arguments to it
     call_user_func_array(array(self::$controller, $action), $actionArguments);
     self::$controller->View->render();
     //renders the View which has been created by Controller's constructor method
 }
開發者ID:romiro,項目名稱:cupcake,代碼行數:55,代碼來源:index.php

示例3: main

 public static function main()
 {
     $time_start = microtime(true);
     require_once 'lib/functions.php';
     session_start();
     header('Content-Type: text/html; charset=UTF-8');
     if (!function_exists('apache_request_headers')) {
         exit('Apache server is required. (PHP function "apache_request_headers" not found)');
     }
     $request_headers = apache_request_headers();
     //get headers for AJAX detection
     define('BASEDIR', dirname(__FILE__));
     define('IS_AJAX', (empty($request_headers['X-Requested-With']) or $request_headers['X-Requested-With'] != 'XMLHttpRequest') ? false : true);
     self::$controller = new Controller();
     self::$controller->View = new View(self::$controller);
     $action = 'index';
     if (!empty($_GET['url'])) {
         $params = explode("/", $_GET['url']);
         $action = preg_replace('/[^a-zA-Z0-9]/', '', $params[0]);
         if (substr($action, 0, 1) == '_') {
             exit("Failure to load pseudo-protected controller action {$action}");
         }
         if (!method_exists('Controller', $action)) {
             exit("Failure to load Controller action <b>{$action}</b>");
         }
     }
     self::$controller->{$action}();
     //runs a method off of the controller named after action param
     self::$controller->View->render();
     //renders the 'view'
     if (IS_AJAX === FALSE) {
         $time_end = microtime(true);
         $time = $time_end - $time_start;
         echo "<!--" . $time . "-->";
     }
 }
開發者ID:romiro,項目名稱:mpcplayer,代碼行數:36,代碼來源:index.php


注:本文中的Dispatcher::controller方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。