本文整理汇总了PHP中Router::action方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::action方法的具体用法?PHP Router::action怎么用?PHP Router::action使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Router
的用法示例。
在下文中一共展示了Router::action方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
示例3: 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);
}
示例4: getAction
public function getAction()
{
if (isset(self::$segments[1])) {
self::$action = self::$segments[1];
} else {
self::$action = 'default';
}
}
示例5: 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];
}
}
示例6: setAction
public static function setAction($str)
{
self::$action = $str;
}
示例7: route
/**
* Определение запрашиваемого модуля и сегмента
*/
public static function route()
{
self::parse_query();
if (self::_check_segments()) {
self::$segment1 = self::$parse['segment1'];
self::$segment2 = self::$parse['segment2'];
self::$segment3 = self::$parse['segment3'];
if (empty(self::$segment1)) {
if (file_exists(ROOT . 'modules/index/execute/index.php')) {
self::$controller_path = 'modules/index/execute/index.php';
self::$controller_name = 'index';
self::$action = '';
self::$page = '';
self::$module = 'index';
} else {
self::$controller_exists = FALSE;
}
} elseif (!empty(self::$segment1) && !empty(self::$segment2)) {
if (file_exists(ROOT . 'modules/' . self::$segment1 . '/execute/' . self::$segment1 . '.php')) {
self::$controller_path = 'modules/' . self::$segment1 . '/execute/' . self::$segment1 . '.php';
self::$controller_name = self::$segment1;
self::$action = self::$segment2;
self::$page = '';
self::$module = self::$segment1;
} else {
self::$controller_exists = FALSE;
}
} elseif (!empty(self::$segment1)) {
if (file_exists(ROOT . 'modules/' . self::$segment1 . '/execute/' . self::$segment1 . '.php')) {
self::$controller_path = 'modules/' . self::$segment1 . '/execute/' . self::$segment1 . '.php';
self::$controller_name = self::$segment1;
self::$action = '';
self::$page = '';
self::$module = self::$segment1;
} else {
self::$controller_exists = FALSE;
}
} else {
throw new Exception('00404');
}
}
if (self::$controller_exists) {
define('ROUTE_CONTROLLER_PATH', self::$controller_path);
define('ROUTE_CONTROLLER_NAME', self::$controller_name);
define('ROUTE_CONTROLLER_URL', self::$module . (self::$action ? '/' . self::$action : '') . (self::$page ? '/' . self::$page : ''));
define('ROUTE_ACTION', self::$action);
define('ROUTE_PAGE', self::$page);
define('ROUTE_MODULE', self::$module);
} elseif (!empty(self::$segment1)) {
if (!empty(self::$segment2)) {
if (is_numeric(self::$segment2)) {
if (!empty(self::$segment3)) {
self::$action = self::$segment3;
} else {
self::$action = "showThread";
}
} else {
self::$action = self::$segment2;
}
} else {
self::$action = "showBoard";
}
define('ROUTE_CONTROLLER_PATH', ROOT . 'modules/index/execute/index.php');
define('ROUTE_CONTROLLER_NAME', 'index');
define('ROUTE_CONTROLLER_URL', self::$segment1);
define('ROUTE_ACTION', self::$action);
define('ROUTE_SEGMENT', self::$segment2);
define('ROUTE_PAGE', self::$segment3);
define('ROUTE_MODULE', 'index');
define('ROUTE_LOGIN', self::$segment1);
} else {
throw new Exception('00404');
}
//;
}
示例8: _init
private function _init()
{
$route = $this->_set_route();
$route = substr($route, -1, 1) == "/" ? substr($route, 0, -1) : $route;
$route = $route ? explode("/", $route) : null;
// define the controller directory
if (isset(self::$config_route['controller_dir_in_route']) && self::$config_route['controller_dir_in_route'] === true) {
if (is_array($route) && count($route)) {
self::$controller_dir = array_shift($route);
} elseif (isset(self::$config_route["default_controller_dir"])) {
self::$config_route["default_controller_dir"];
} else {
trigger_error("ROUTER: DEFAULT CONTROLLER DIR NOT SET");
}
}
// define the controller
if (is_array($route) && count($route)) {
self::$controller = array_shift($route);
} elseif (isset(self::$config_route['default_controller'])) {
self::$controller = self::$config_route["default_controller"];
} else {
trigger_error("ROUTER: DEFAULT CONTROLLER NOT SET");
}
// define action
if (is_array($route) && count($route)) {
self::$action = array_shift($route);
} elseif (isset(self::$config_route['default_action'])) {
self::$action = self::$config_route['default_action'];
} else {
trigger_error("ROUTER: DEFAULT ACTION NOT SET");
}
// define the parameters
if ($route) {
self::$params = $route;
}
}
示例9: 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 = 'home';
}
if (!strlen(self::$action)) {
self::$action = 'index';
}
}
示例10: parse
public static function parse($uri)
{
self::$action = Config::get('default_action');
self::$controller = Config::get('default_controller');
self::$language = Config::get('default_language');
self::$id = Config::get('default_id');
$uri_elements = self::url_to_array($uri);
if (count($uri_elements)) {
//if (strtolower(current($uri_elements) != 'admiin')) {
if (in_array(strtolower(current($uri_elements)), Config::get('languages'))) {
self::$language = strtolower(current($uri_elements));
array_shift($uri_elements);
}
//}else {
// array_shift($uri_elements);
//}
$url = implode('/', $uri_elements);
self::find_alias($url);
/**
if(current($uri_elements)){
self::$controller = ucfirst(strtolower(current($uri_elements)));
array_shift($uri_elements);
}
if(current($uri_elements)){
self::$action = strtolower(current($uri_elements));
array_shift($uri_elements);
}
if(current($uri_elements)){
self::$params = $uri_elements;
}
**/
}
}