本文整理汇总了PHP中Router::controller方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::controller方法的具体用法?PHP Router::controller怎么用?PHP Router::controller使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Router
的用法示例。
在下文中一共展示了Router::controller方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public static function init()
{
$url = $_SERVER['REQUEST_URI'];
$isCustom = false;
if (count(self::$rules)) {
foreach (self::$rules as $ruleKey => $ruleData) {
$params = self::ruleMatch($ruleKey, $url);
if ($params) {
self::$controller = $ruleData['controller'];
self::$action = $ruleData['action'];
self::$params = $params;
$isCustom = true;
break;
}
}
}
if (!$isCustom) {
self::defaultRoutes($url);
}
if (!strlen(self::$controller)) {
self::$controller = 'site';
}
if (!strlen(self::$action)) {
self::$action = '';
}
if (self::$action == ':site') {
self::$action = self::getParam("site");
}
}
示例2: 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;
}
}
示例3: parse
/**
* @param $url
* @throws Exception
*/
public static function parse($url)
{
$arr = explode('?', $url);
$url = rtrim($arr[0], '/');
if (!$url) {
self::$controller = 'IndexController';
self::$action = 'indexAction';
return;
}
foreach (self::$routes as $route => $item) {
$regex = $item['pattern'];
foreach ($item['params'] as $k => $v) {
$regex = str_replace('{' . $k . '}', '(' . $v . ')', $regex);
}
if (preg_match('@^' . $regex . '$@', $url, $matches)) {
array_shift($matches);
if ($matches) {
foreach ($item as $k1 => $v1) {
$matches = array_combine(array_keys($item['params']), $matches);
}
}
self::$controller = $item['controller'] . 'Controller';
self::$action = $item['action'] . 'Action';
$_GET = $matches + $_GET;
break;
}
}
if (is_null(self::$controller) || is_null(self::$action)) {
throw new Exception('Page not found', 404);
}
}
示例4: parse
/**
* @param $url
* @throws Exception
* Метод для парсинга урла
*/
public static function parse($url)
{
$arr = explode('?', $url);
$url = rtrim($arr[0], '/');
// если пусто - то на главную
if (!$url) {
self::$controller = 'IndexController';
self::$action = 'indexAction';
return;
}
// перебор роутов на предмет совпадения решулярки с урлом
foreach (self::$routes as $route => $item) {
$regex = $item['pattern'];
foreach ($item['params'] as $k => $v) {
$regex = str_replace('{' . $k . '}', '(' . $v . ')', $regex);
}
// если совпало
if (preg_match('@^' . $regex . '$@', $url, $matches)) {
array_shift($matches);
if ($matches) {
foreach ($item as $k1 => $v1) {
$matches = array_combine(array_keys($item['params']), $matches);
}
}
// определяем названия класса/метода контроллера
self::$controller = $item['controller'] . 'Controller';
self::$action = $item['action'] . 'Action';
$_GET = $matches + $_GET;
break;
}
}
if (is_null(self::$controller) || is_null(self::$action)) {
throw new Exception('Page not found', 404);
}
}
示例5: init
private function init()
{
//get user requested route
if (isset($_GET['node'])) {
//define route without parameters (helps with showing base URI request)
$route = $_GET['node'];
self::$route = $route;
//break requested route into chunks in array
$route_chunks = explode("/", $route);
//define controller
$controller = $route_chunks[0];
self::$controller = $controller;
//define controller directory
$controller_dir = CONTROLLER_DIR . $controller;
self::$controller_dir = $controller_dir;
//define format
if (!empty($route_chunks[1])) {
$format = $route_chunks[1];
self::$format = $format;
}
//define parameters - get full url etc and extract all strings after &..
global $settings;
$request_uri = $settings['request_uri'];
//break requested route into chunks in array
$route_params = explode("&", $request_uri);
//remove first value from array & return $route_params as just parameters
$params_shift = array_shift($route_params);
//update $params array
foreach ($route_params as $val) {
$param_chunks = explode("=", $val);
$params[$param_chunks[0]] = $param_chunks[1];
}
self::$params = $params;
}
}
示例6: explode
static function route_controller($applicationName)
{
$url = parse_url($_SERVER['REQUEST_URI']);
$path = explode('/', trim($url['path'], '/'));
if (!isset($path[1])) {
self::$controller = 'index';
self::$action = 'index';
} else {
array_shift($path);
$dir = $applicationName . '/controllers/';
foreach ($path as $p) {
if (!is_dir($dir . $p . '/')) {
break;
} else {
$dir .= $p . '/';
array_shift($path);
}
}
self::$dir = $dir;
//if (isset($path[0]) and $path[0] == 'index.php')
self::$controller = array_shift($path);
self::$action = array_shift($path);
if (empty(self::$action)) {
self::$action = 'index';
}
}
foreach ($path as $k => $v) {
self::$params[$k] = $v;
}
return array(self::$controller, self::$action, self::$params);
}
示例7: 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';
}
}
示例8: getController
public function getController()
{
if (isset(self::$segments[0])) {
self::$controller = self::$segments[0];
} else {
self::$controller = 'index';
}
}
示例9:
/**
* 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";
}
}
示例10: pareUrl
public static function pareUrl()
{
if (isset($_GET['r'])) {
$query_string = $_GET['r'];
$query_string = explode('/', $query_string);
self::$controller = $query_string[0];
self::$action = $query_string[1];
}
}
示例11: trim
/**
* Add the chroot path at the begining of the requested URI
*/
static function parse_url()
{
if (user_chroot::album()) {
if (Router::$controller == 'albums' && Router::$current_uri == '') {
// Root album requested
Router::$controller = null;
Router::$current_uri = trim(user_chroot::album()->relative_url() . '/' . Router::$current_uri, '/');
} else {
if (is_null(Router::$controller) && Router::$current_uri != '') {
// Non-root album requested
Router::$current_uri = trim(user_chroot::album()->relative_url() . '/' . Router::$current_uri, '/');
}
}
}
return parent::parse_url();
}
示例12: 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;
}
}
示例13: setUp
protected function setUp()
{
// Save config
$this->kohana_config['core.url_suffix'] = Kohana_Config::instance()->get('core.url_suffix');
// Save Server API
$this->kohana_server_api = Kohana::$server_api;
// Save Router members
$this->router_vars = array('complete_uri' => Router::$complete_uri, 'controller' => Router::$controller, 'current_uri' => Router::$current_uri, 'query_string' => Router::$query_string, 'rsegments' => Router::$rsegments, 'routed_uri' => Router::$routed_uri, 'segments' => Router::$segments, 'url_suffix' => Router::$url_suffix);
// Reset Router members
Router::$complete_uri = '';
Router::$controller = NULL;
Router::$current_uri = '';
Router::$query_string = '';
Router::$rsegments = NULL;
Router::$routed_uri = '';
Router::$segments = NULL;
Router::$url_suffix = '';
}
示例14:
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;
}
}
示例15: 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);
}
}