本文整理汇总了PHP中Router::method方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::method方法的具体用法?PHP Router::method怎么用?PHP Router::method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Router
的用法示例。
在下文中一共展示了Router::method方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: count
static function parse_url()
{
if (Router::$controller) {
return;
}
// Work around problems with the CGI sapi by enforcing our default path
if ($_SERVER["SCRIPT_NAME"] && "/" . Router::$current_uri == $_SERVER["SCRIPT_NAME"]) {
Router::$controller_path = MODPATH . "gallery/controllers/albums.php";
Router::$controller = "albums";
Router::$method = 1;
return;
}
$current_uri = html_entity_decode(Router::$current_uri, ENT_QUOTES);
$item = ORM::factory("item")->where("relative_path_cache", $current_uri)->find();
if (!$item->loaded) {
// It's possible that the relative path cache for the item we're looking for is out of date,
// so find it the hard way.
$count = count(Router::$segments);
foreach (ORM::factory("item")->where("name", html_entity_decode(Router::$segments[$count - 1], ENT_QUOTES))->where("level", $count + 1)->find_all() as $match) {
if ($match->relative_path() == $current_uri) {
$item = $match;
}
}
}
if ($item && $item->loaded) {
Router::$controller = "{$item->type}s";
Router::$controller_path = MODPATH . "gallery/controllers/{$item->type}s.php";
Router::$method = $item->id;
}
}
示例2: scan
private static function scan($force = FALSE)
{
$found = FALSE;
if (!self::$scanned || $force) {
foreach (self::$routes as $priority => $routes) {
if ($found) {
break;
}
foreach ($routes as $route) {
if ($found) {
break;
}
unset($ctrl, $redirect);
list($pattern, $replacement, $method, $source) = $route;
switch ($method) {
case self::ROUTE_STATIC:
if (URI_PATH === $pattern) {
$ctrl = $replacement;
}
break;
case self::ROUTE_PCRE:
if (preg_match($pattern, URI_PATH)) {
$ctrl = preg_replace($pattern, $replacement, URI_PATH);
}
break;
case self::REDIRECT_STATIC:
if (URI_PATH === $pattern) {
$redirect = $replacement;
}
break;
case self::REDIRECT_PCRE:
if (preg_match($pattern, URI_PATH)) {
$redirect = preg_replace($pattern, $replacement, URI_PATH);
}
break;
}
if (isset($ctrl) || isset($redirect)) {
if (isset($ctrl) && is_readable($ctrl)) {
self::$pattern = $pattern;
self::$ctrl = $ctrl;
self::$method = $method;
self::$source = $source;
$found = TRUE;
}
}
}
}
if (!self::$ctrl && !isset($redirect) && substr(URI_PATH, -1) !== '/') {
$redirect = URI_PATH . '/';
if (strlen(URI_PARAM)) {
$redirect .= '?' . URI_PARAM;
}
}
if (isset($redirect)) {
header('Location: ' . $redirect);
exit;
}
self::$scanned = !$force;
}
}
示例3: __construct
/**
* Constructor.
* Acts as mini Router that picks up at the Controller level, post-routing.
* Searches for files in directory relative to delegating class.
*
* Uses argument already set in Router as provided in URL.
*
* The URL parameter that would ordinarily be the method is now the subdirectory
* The URL parameter that would be the first method parameter is now the controller.
* The URL paramter that would be the second method parameter is now the method.
*
* Any remaining URL parameters are passed along as method parameters for the
* Subcontroller invoked.
*/
public function __construct()
{
// Find the file in the directory relative to the original Controller.
$subdirectory = dirname($this->file) . '/' . Router::$method;
$file = strtolower(array_shift(Router::$arguments));
$path = $subdirectory . '/' . $file . FILE_EXTENSION;
$default_path = $subdirectory . '/' . Router::$method . FILE_EXTENSION;
if (file_exists($path)) {
Loader::load($path);
$controller = ucfirst($file) . '_Controller';
if (count(Router::$arguments)) {
Router::$method = array_shift(Router::$arguments);
} else {
Router::$method = Registry::$config['core']['default_controller_method'];
}
Core::run_controller($controller);
} elseif (file_exists($default_path)) {
// Check for a default file of the same name as the directory, and load that with the default method.
Loader::load($default_path);
$controller = ucfirst(strtolower(Router::$method)) . '_Controller';
Router::$method = Registry::$config['core']['default_controller_method'];
Core::run_controller($controller);
} else {
// No matches.
Core::error_404();
}
// Exit to prevent Router from continuing in Core.
exit;
}
示例4: call_fallback_page
function call_fallback_page()
{
if (Router::$controller === NULL) {
Router::$controller = 'fallback_page';
Router::$method = 'find_view';
Router::$controller_path = APPPATH . 'controllers/fallback_page.php';
}
}
示例5:
/**
* If Gallery is in maintenance mode, then force all non-admins to get routed to a "This site is
* down for maintenance" page.
*/
static function maintenance_mode()
{
$maintenance_mode = Kohana::config("core.maintenance_mode", false, false);
if (Router::$controller != "login" && !empty($maintenance_mode) && !user::active()->admin) {
Router::$controller = "maintenance";
Router::$controller_path = MODPATH . "gallery/controllers/maintenance.php";
Router::$method = "index";
}
}
示例6: parse
public static function parse($url)
{
$url = rtrim($url, '/');
$url = explode('/', $url);
if ($url[0]) {
self::$name = ucfirst(strtolower($url[0]));
}
self::$method = $url[1];
self::$params = array();
if (count($url) > 2) {
//есть параметры
for ($i = 2; $i < count($url); $i++) {
self::$params[] = $url[$i];
}
}
}
示例7: count
static function parse_url()
{
if (Router::$controller) {
return;
}
$count = count(Router::$segments);
foreach (ORM::factory("item")->where("name", Router::$segments[$count - 1])->where("level", $count + 1)->find_all() as $match) {
if ($match->relative_path() == Router::$current_uri) {
$item = $match;
}
}
if (!empty($item)) {
Router::$controller = "{$item->type}s";
Router::$controller_path = APPPATH . "controllers/{$item->type}s.php";
Router::$method = $item->id;
}
}
示例8: setMethod
public static function setMethod()
{
$method = strtolower($_SERVER['REQUEST_METHOD']);
if ((SITE == 'dev' or SITE == 'stage') and isset($_GET['method'])) {
$method = $_GET['method'];
unset($_GET['method']);
}
if ($method == 'post') {
if (self::$subresource == 'collection' or self::$subresource == 'throttles' or strpos(self::$resource, 'budget') !== false or self::$resource == 'token' and !self::$id or self::$resource == 'sim') {
$method = 'add';
} else {
$method = 'set';
}
}
unset($_GET['method']);
self::$method = $method;
}
示例9:
static function parse_url()
{
if (Router::$controller) {
return;
}
// Work around problems with the CGI sapi by enforcing our default path
if ($_SERVER["SCRIPT_NAME"] && "/" . Router::$current_uri == $_SERVER["SCRIPT_NAME"]) {
Router::$controller_path = MODPATH . "gallery/controllers/albums.php";
Router::$controller = "albums";
Router::$method = 1;
return;
}
$item = self::get_item_from_uri(Router::$current_uri);
if ($item && $item->loaded) {
Router::$controller = "{$item->type}s";
Router::$controller_path = MODPATH . "gallery/controllers/{$item->type}s.php";
Router::$method = $item->id;
}
}
示例10: array
static function parse_url()
{
if (Router::$controller) {
return;
}
// Work around problems with the CGI sapi by enforcing our default path
if ($_SERVER["SCRIPT_NAME"] && "/" . Router::$current_uri == $_SERVER["SCRIPT_NAME"]) {
Router::$controller_path = MODPATH . "gallery/controllers/albums.php";
Router::$controller = "albums";
Router::$method = 1;
return;
}
$item = item::find_by_relative_url(html_entity_decode(Router::$current_uri, ENT_QUOTES));
if ($item && $item->loaded()) {
Router::$controller = "{$item->type}s";
Router::$controller_path = MODPATH . "gallery/controllers/{$item->type}s.php";
Router::$method = "show";
Router::$arguments = array($item);
}
}
示例11: operation
public static function operation()
{
$filepath = Router::controller('filepath');
$classname = Router::controller('classname');
$method = Router::method();
$arguments = Router::arguments();
//加载controller
if (file_exists($filepath)) {
Zotop::load($filepath);
}
if (class_exists($classname, false)) {
$controller = new $classname();
if (method_exists($controller, $method) && $method[0] != '_') {
call_user_func_array(array($controller, $method), $arguments);
} else {
//Zotop::run('system.status.404');
//当方法不存在时,默认调用类的_empty()函数,改函数默认显示一个404错误,你可以在控制器中重写此方法
call_user_func_array(array($controller, '_empty'), $arguments);
}
} else {
Zotop::run('system.status.404');
}
}
示例12: ReflectionClass
/**
* If the gallery is only available to registered users and the user is not logged in, present
* the login page.
*/
static function private_gallery()
{
if (identity::active_user()->guest && !access::user_can(identity::guest(), "view", item::root()) && php_sapi_name() != "cli") {
try {
$class = new ReflectionClass(ucfirst(Router::$controller) . '_Controller');
$allowed = $class->getConstant("ALLOW_PRIVATE_GALLERY") === true;
} catch (ReflectionClass $e) {
$allowed = false;
}
if (!$allowed) {
if (Router::$controller == "admin") {
// At this point we're in the admin theme and it doesn't have a themed login page, so
// we can't just swap in the login controller and have it work. So redirect back to the
// root item where we'll run this code again with the site theme.
url::redirect(item::root()->abs_url());
} else {
Session::instance()->set("continue_url", url::abs_current());
Router::$controller = "login";
Router::$controller_path = MODPATH . "gallery/controllers/login.php";
Router::$method = "html";
}
}
}
}
示例13: init
public function init()
{
$uri = explode('?', $_SERVER['REQUEST_URI']);
$uri = explode('/', $uri[0]);
if (count($uri) < 3 or $uri[2] == '') {
Router::$objectName = 'Index';
} else {
Router::$objectName = $uri[2];
}
Router::$object = RESTObject::objectFactory();
switch ($_SERVER['REQUEST_METHOD']) {
case 'POST':
Router::$method = Router::POST;
break;
case 'PUT':
Router::$method = Router::PUT;
break;
case 'DELETE':
Router::$method = Router::DELETE;
break;
default:
Router::$method = Router::GET;
}
}
示例14: current
/**
* Determines the appropriate controller, method, and arguments
* from the current URI request.
* Where necessary, defaults will be employed.
* Values are stored in local static members for use by the core.
*/
public static function current()
{
$current = $_SERVER['PHP_SELF'];
// Are we being run from command line?
if (PHP_SAPI === 'cli') {
// $argv and $argc are disabled by default in some configurations.
$argc = isset($argc) ? $argc : $_SERVER['argc'];
if ($argc > 0) {
$args = isset($argv) ? $argv : $_SERVER['argv'];
// Merge all cli arguments as if they were in a uri from web context.
$current = implode('/', $args);
} else {
$current = $_SERVER['PHP_SELF'];
}
}
// Remove dot paths
$current = preg_replace('#\\.[\\s./]*/#', '', $current);
// Remove leading slash
$current = ltrim($current, '/');
// Reduce multiple slashes
$current = preg_replace('#//+#', '/', $current);
// Remove front controller from URI
$current = ltrim($current, Registry::$config['core']['front_controller'] . FILE_EXTENSION);
// Remove any remaining leading/trailing slashes
$current = trim($current, '/');
$parts = array();
if (strlen($current) > 0) {
$parts = explode('/', $current);
}
/**
* The controller is expected to be the first part.
* If not supplied, we'll assume the default controller
* defined in config.
*
* The method, if supplied, is expected to be the second part.
* If not supplied, we'll assume that the default method defined
* in config is the intended method.
*
* Any remaining parts are presumed to be arguments to the
* method and will be treated as such.
*/
if (count($parts)) {
self::$controller = array_shift($parts);
} else {
self::$controller = Registry::$config['core']['default_controller'];
}
if (count($parts)) {
self::$method = array_shift($parts);
} else {
self::$method = Registry::$config['core']['default_controller_method'];
}
if (count($parts)) {
self::$arguments = $parts;
}
}
示例15: process_request
/**
* Cleans any supplied suffixes out of the URI
*
* @return void
* @author Sam Clark
* @access protected
*/
public function process_request()
{
// Launch a Restful preprocessing event
Event::run('restful.pre_processing', $this);
if ($this->config['caching']) {
// Load the cache name
$cache_name = $this->get_cache_name();
if ($cached = $this->cache->get($cache_name)) {
Router::$method = $cached['method'];
Router::$arguments = $cached['args'];
self::$mime = $cached['mime'];
self::$http_method = $cached['http_method'];
Event::run('restful.post_processing', $this);
return;
}
}
// First check the Routers own detection
if (Router::$url_suffix !== '') {
$ext = ltrim(Router::$url_suffix, '.');
if (array_key_exists($ext, $this->config['supported_mimes'])) {
self::$mime = array('extension' => $ext, 'type' => Kohana::config('mimes.' . $ext . '.0'));
}
} else {
// If there are Router arguments, the extension will be here
if (Router::$arguments) {
// Remove any supplied extension applied to the last argument before controller processing
Router::$arguments[] = preg_replace_callback($this->config['supported_mimes'], array($this, 'replace_mime'), array_pop(Router::$arguments), 1);
} else {
// Clean the router method
Router::$method = preg_replace_callback($this->config['supported_mimes'], array($this, 'replace_mime'), Router::$method, 1);
}
}
// Try and detect the HTTP method
self::$http_method = $this->detect_http_method();
// Cache the process if required
if ($this->config['caching']) {
$this->cache->set($cache_name, array('method' => Router::$method, 'args' => Router::$arguments, 'mime' => self::$mime, 'http_method' => self::$http_method), array('mime'), $this->config['caching'] === TRUE ? NULL : $this->config['caching']);
}
// If auto send header is set to true, send the content-type header
if ($this->config['auto_send_header']) {
header('Content-Type: ' . self::$mime['type']);
}
// Launch a post processing event
Event::run('restful.post_processing', $this);
return;
}