当前位置: 首页>>代码示例>>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;未经允许,请勿转载。