本文整理汇总了PHP中Route::run方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::run方法的具体用法?PHP Route::run怎么用?PHP Route::run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Route
的用法示例。
在下文中一共展示了Route::run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* function that launch the framework
* @param void
* @return bool
**/
public static function render() : bool
{
self::get('confs');
self::get(DIR_MODELS);
self::get(DIR_CONTROLLERS);
// ------------------------------------------------------------------------
// get arguments
$args = array_merge($_GET, $_POST);
if (empty($args['url'])) {
$args['url'] = '/';
}
try {
// ------------------------------------------------------------------------
// load external librairies
Server::loadLibs();
// ------------------------------------------------------------------------
// allow storage for all applications
Storage::init();
// ------------------------------------------------------------------------
// allow access to database
Database::autoConnect();
// ------------------------------------------------------------------------
// launch controller
if (!empty($args['task'])) {
Task::exec($args['task'], $args);
} else {
Route::run($args['url'], $args);
}
} catch (Exception $e) {
echo $e->getMessage();
}
return true;
}
示例2: start
static function start()
{
self::boot();
// 函数库
require CORE_PATH . 'load.php';
load::register();
// 自动加载,没有找到本地类的
register_shutdown_function('\\poem\\app::appFatal');
// 错误和异常处理
set_error_handler('\\poem\\app::appError');
set_exception_handler('\\poem\\app::appException');
t('POEM_TIME');
$module = defined('NEW_MODULE') ? NEW_MODULE : 'home';
if (!is_dir(APP_PATH . $module)) {
\poem\more\Build::checkModule($module);
}
Route::run();
// 路由管理
self::exec();
// 执行操作
t('POEM_TIME', 0);
if (!config('debug_trace') || IS_AJAX || IS_CLI) {
exit;
}
log::show();
exit;
}
示例3: __construct
private function __construct(){
$this->load_paths();
$this->load_controllers();
$this->load_globals();
Route::run();
$this->delegate_to_controller();
exit;
}
示例4: post
static function post($uri, $controller, $vars = [])
{
if (Route::$status) {
return false;
}
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
return false;
}
Route::run($uri, $controller, $vars);
}
示例5: run
/**
* Run the app, parsing the requested URL and dispatching to the appropriate Route
* @internal \Microsite\App|null $parent
* @return bool|string Upon successful execution, the string of output produced, otherwise false
*/
public function run()
{
try {
$do_output = false;
$has_output = false;
$response = $this->response();
if (!$response->did_output) {
$response->did_output = true;
$do_output = true;
}
$output = false;
foreach ($this->routes as $route) {
/** @var Route $route */
if ($route->match($this) && ($this->route == null || $this->route->match_type() < $route->match_type() && $this->route->get_url() == $route->get_url())) {
$this->route = $route;
}
}
if (isset($this->route)) {
foreach ($this->middleware as $middleware) {
$this->exec_params($middleware);
}
$result = $this->route->run($this);
if ($result) {
$output = (string) $result;
$has_output = true;
}
}
if ($do_output) {
if ($has_output) {
echo $output;
} else {
$this->header('HTTP/1.1 404 Not Found');
echo $response->render('404.php');
}
}
return $output;
} catch (\Exception $e) {
$response['error'] = $e;
$this->header('HTTP/1.1 500 Internal Server Error');
if ($response instanceof Response) {
$output = $response->render('error.php');
} else {
$output = var_export($e, true);
}
}
echo $output;
return $output;
}
示例6: Route
<?php
/**
* Routing system
*/
$route = new Route();
// User define function
$route->add('/h', function () {
echo 'hey this is home page';
});
// Routing controller
$route->add('/login', 'login');
$route->add('/account', 'account');
$route->add('/dashboard', 'dashboard');
$route->add('/error', 'error');
$route->add('/home', 'home');
//
$route->run();
示例7:
<?php
require_once '../lib/bootstrap.inc.php';
Route::map_connect(array('controller' => 'test1', 'path' => '', 'method' => 'GET', 'action' => 'index'));
Route::map_connect(array('controller' => 'test1', 'path' => 'items/:id', 'method' => 'GET', 'action' => 'show_item'));
Route::map_connect(array('controller' => 'test1', 'path' => 'blogs/:blog_id/archives/:year', 'method' => 'GET', 'action' => 'show_blog_yearly_archives'));
Route::run();
示例8:
require $file;
}
}
});
use Socio\Database;
use Socio\Settings;
use Socio\Event;
$config = (include 'config.php');
Socio\Settings::init($config);
Database::init();
/*$user = User::get(array('id' => '20'));
$user->name = "potter";
$user->gender = "f";
$user->save();*/
Plugin::register();
Socio\Event::fire("framework_ready");
$r = $_GET['r'];
if (isset($r)) {
Route::post("register", "RegisterController");
Route::get("register", "RegisterController");
Route::get("login", "LoginController");
Route::post("login", "LoginController");
Route::get("home", "HomeController");
Route::post("home", "HomeController");
Route::get("logout", "LogoutController");
Route::get("profile/{param}", "ProfileController");
Route::post("profile/{param}", "ProfileController");
Route::run($r);
} else {
echo "You dont have access";
}
示例9: initRoute
/**
* The function initializes router feature.
*
* @static
* @access private
*/
private static function initRoute()
{
Route::run(Request::get('REQUEST_URI', '/', 'SERVER'));
$host = strtolower(Config::get('host'));
if ($host) {
$sub = trim(str_replace($host, '', preg_replace('/^www\\./', '', strtolower(Runtime::get('HTTP_HOST')))), '.');
if (!$sub) {
$sub = 'www';
}
Runtime::set('HTTP_SUBDOMAIN', $sub);
}
$controller = 0;
$args = array();
$path = Route::get();
Runtime::set('REQUEST_URI', '/' . implode('/', $path));
if (!is_array($path)) {
$path = ltrim('/', explode('/', $path));
}
$values = $path;
$link = '/';
for ($i = 0; $i < count($values); $i++) {
$arr = array_slice($values, 0, count($values) - $i);
$link = '/' . implode('/', $arr);
$controller = Route::getController($link);
if ($controller) {
$args = array_slice($values, count($values) - $i);
break;
}
}
if (!$controller) {
$controller = Route::getController('/');
$args = $values;
}
if (!$controller) {
echo "No controller found: /" . implode('/', $path) . "\n";
exit;
}
Runtime::set('ROUTING_CONTROLLER', $controller);
Runtime::set('ROUTING_ROUTER', Route::getRouter($link));
Runtime::set('ROUTING_ARGUMENTS', $args);
}
示例10: controller
public function controller($path, $args = array())
{
$route = new Route($path, $args);
return $route->run($this->registry);
}
示例11: function
});
// render a post
Route::get('show_post', function ($args) {
$partial_article = file_get_contents(ROOT . '/templates/' . THEME . '/partials/article.html');
$partial_category = file_get_contents(ROOT . '/templates/' . THEME . '/partials/category.html');
$post_id = isset($args['post_id']) ? (int) $args['post_id'] : NULL;
$post = new Post($post_id);
$articles = PostRender::renderPost(new Post($post_id), $partial_article);
$categories = CategoryRender::render($post->category_id, $partial_category);
render_content(['articles' => $articles, 'category' => $categories]);
});
// default action
Route::get('', function ($args) {
$category_id = 1;
$year = !empty($args['year']) ? (int) $args['year'] : date('Y');
Route::run('show_category', ['category_id' => $category_id, 'year' => $year]);
});
// render page content
function render_content($replaces)
{
$content = new Content(1);
$layout_content = file_get_contents(ROOT . '/templates/' . THEME . '/layout.html');
$layout_content = str_replace('{theme}', THEME, $layout_content);
$layout_content = str_replace('{url}', $_SERVER['SCRIPT_NAME'], $layout_content);
$layout_content = str_replace('{title}', $content->title, $layout_content);
$layout_content = str_replace('{subtitle}', $content->subtitle, $layout_content);
$layout_content = str_replace('{sidepanel}', $content->sidepanel, $layout_content);
foreach ($replaces as $key => $value) {
$layout_content = str_replace('{' . $key . '}', $value, $layout_content);
}
echo $layout_content;
示例12: exit
<?php
define('VERSION', '0.1.b');
if (file_exists('config.php')) {
require_once 'config.php';
}
if (!defined('APP_DIR')) {
exit('config file not available ');
}
//startup.php pre-loads all initial files
require_once APP_SYSTEM . 'startup.php';
$registry = new Registry();
$loader = new Loader($registry);
$registry->set('load', $loader);
$request = new Request();
$registry->set('request', $request);
// Database
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$registry->set('db', $db);
if (isset($request->get['url']) && isset($request->get['args'])) {
$route = new Route($request->get['url'], $request->get['args']);
} else {
if (isset($request->get['url'])) {
$route = new Route($request->get['url']);
} else {
$route = new Route('common/home');
}
}
echo $route->run($registry);
示例13: Route
<?php
/**
* Created by PhpStorm.
* User: Boris
* Date: 09.10.2015
* Time: 11:13
*/
header("Content-Type: text/html; charset=utf-8");
require_once '../config.php';
require_once PATH_BASE . '/core/Route.php';
$start = new Route($route);
$start->run();
示例14: run
public function run()
{
Route::run();
}
示例15: run
/**
* Run Core
*/
public function run()
{
/**
* Require main helper
*/
require FW_PATH . 'Helpers/file.php';
require FW_PATH . 'Helpers/log.php';
require FW_PATH . 'Helpers/input.php';
require FW_PATH . 'Helpers/error.php';
require FW_PATH . 'Helpers/url.php';
require FW_PATH . 'Helpers/config.php';
/**
* Check assets request
*/
if (self::isAssetsRequest(URI::getURI())) {
exit;
}
/**
* Require app config
*/
if (file_exists(APP_PATH . 'Config/app.php')) {
$config = (require APP_PATH . 'Config/app.php');
if (is_array($config) && $config !== null) {
foreach ($config as $key => $value) {
$GLOBALS['config'][$key] = $value;
}
}
} elseif (APP_ENV === 'development') {
error_dump('File \'' . APP_PATH . 'Config/app.php\' not found!');
die;
}
/**
* Require database config
*/
if (file_exists(APP_PATH . 'Config/database.php')) {
$config = (require APP_PATH . 'Config/database.php');
if (is_array($config) && $config !== null) {
foreach ($config as $key => $value) {
$GLOBALS['config'][$key] = $value;
}
}
} elseif (APP_ENV === 'development') {
error_dump('File \'' . APP_PATH . 'Config/database.php\' not found!');
die;
}
/**
* Require mimes config
*/
if (file_exists(APP_PATH . 'Config/mimes.php')) {
$config = (require APP_PATH . 'Config/mimes.php');
if (is_array($config) && $config !== null) {
foreach ($config as $key => $value) {
$GLOBALS['config'][$key] = $value;
}
}
} elseif (APP_ENV === 'development') {
error_dump('File \'' . APP_PATH . 'Config/mimes.php\' not found!');
die;
}
$this->handleAutoload();
Route::run();
}