本文整理汇总了PHP中core\Router类的典型用法代码示例。如果您正苦于以下问题:PHP Router类的具体用法?PHP Router怎么用?PHP Router使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Router类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$iID = $this->post('id');
$iAccountID = $this->post('account_id');
(new m\Account())->del($iID);
c\Router::redirect(c\Router::genURL('Detail', ['id' => $iAccountID]));
}
示例2: start
/**
* 启动程序
* @return [type] [description]
*/
public function start()
{
$this->init();
//数据库初使化
DB::init();
//路由初使化
Router::init();
//TODO:: 还需要支持自定义的路由
if (file_exists(APP_PATH . 'config/Router.php')) {
}
//调用控制器
$controllerFile = APP_PATH . MODULE . 'controller/' . CONTROLLER . CLASS_EXT;
if (file_exists($controllerFile)) {
include_once $controllerFile;
$controller = MODULE ? MODULE : "Controller" . '\\' . CONTROLLER;
$action = ACTION;
$obj = new $controller();
if (method_exists($obj, $action)) {
$obj->{$action}();
} else {
throw new \Exception("非法操作: " . ACTION);
}
} else {
throw new \Exception("无法加载控制器: " . CONTROLLER);
}
}
示例3: run
public function run()
{
$iAccountID = $this->get('id');
$oAccount = new m\Account();
$aDetail = $oAccount->getAccountDetail($iAccountID);
if (empty($aDetail)) {
c\Router::redirect(c\Router::genURL('Home'));
}
$aFields = $oAccount->getAccountFields($iAccountID);
$oUser = new m\User();
$aDefaultPassword = $oUser->getDefaultPassword();
$aEmails = $oUser->getEmails();
foreach ($aFields as $k => $v) {
$aFields[$k]['display'] = u\Str::partCover($v['value'], 2, 1);
}
sort($aFields);
$aFieldNames = array_map(function ($v) {
foreach ($v as $key => $value) {
if ($key !== 'name') {
unset($v[$key]);
}
}
return $v;
}, $aFields);
$aAccountAll = $oAccount->getAllAccount();
$aSiteList = [];
foreach ($aAccountAll as $aAccountDetail) {
$aSiteList[] = ['name' => 'link:' . $aAccountDetail['name']];
}
$aData = ['page_title' => 'Open Sesame - ' . $aDetail['name'], 'app' => $aDetail, 'fields' => $aFields, 'form_action_add' => c\Router::genURL('AddField'), 'form_action_del' => c\Router::genURL('DeleteField'), 'form_action_updatefield' => c\Router::genURL('UpdateField'), 'form_action_updateaccount' => c\Router::genURL('UpdateAccount'), 'site_list' => json_encode($aSiteList), 'field_names' => json_encode($aFieldNames), 'default_password' => $aDefaultPassword['data'], 'emails' => $aEmails['data']];
return $aData;
}
示例4: redirect
/**
*Redirect
**/
public function redirect($url, $code = null)
{
if ($code == 301) {
header("HTTP/1.1 301 Moved Permanently");
}
header("location: " . Router::url($url));
}
示例5: run
public function run()
{
error_reporting(Config::get('app.debug') ? E_ALL : 0);
//Set Date Timezone
date_default_timezone_set(Config::get('app.timezone'));
//Set Cache Ctatus
ini_set('opcache.revalidate_freq', Config::get('app.cache') ? '0' : '1');
try {
static::stripTraillingSlash();
$this->session->start();
Router::init();
$routerParams = Router::getParams();
$this->handleMiddlewares($routerParams);
$controllerParams = [];
foreach ($routerParams as $paramName => $paramValue) {
if (substr($paramName, 0, 1) != '_') {
$controllerParams[$paramName] = $paramValue;
}
}
if (isset($routerParams['_params']) && is_array($routerParams['_params'])) {
foreach ($routerParams['_params'] as $paramName => $paramValue) {
$controllerParams[$paramName] = $paramValue;
}
}
$controllerFullName = '\\App\\Controllers\\' . $routerParams['_controller'];
try {
return $this->di->call($controllerFullName . '::' . $routerParams['_method'], $controllerParams);
} catch (Exception $e) {
new ExceptionHandler($e);
}
} catch (Exception $e) {
new ExceptionHandler($e);
}
return true;
}
示例6: run
public function run($config)
{
$this->extr($config);
//раскручиваем конфиг
Router::init()->run();
//вызываем роутер
}
示例7: __construct
public function __construct()
{
$app = App::getInstance();
// On initialise l'objet Request
if ($_ENV['USE_ROUTES']) {
require '../Config/routes.php';
$this->request = Router::run(new Request($app));
} else {
$this->request = new Request($app);
}
// On parse l'url (définition du controller, action,...)
Router::parse($this->request);
// On affiche les erreurs ?
Debug::set();
// On charge le bon controller
try {
$controller = $this->loadController();
} catch (SwithException $e) {
(new SwithError(['message' => "Le controller {$this->request->controller} est introuvable", "title" => "Controlleur introuvable"]))->display();
}
if (method_exists($controller, "beforeRender")) {
$controller->beforeRender();
}
// On appelle la fonction
$action = $this->request->getAction();
$availablesActions = array_diff(get_class_methods($controller), get_class_methods(get_parent_class($controller)));
if (in_array($action, $availablesActions)) {
call_user_func_array([$controller, $action], $this->request->params);
} else {
(new SwithError(['message' => "Le controller {$this->request->controller} n'a pas de methode {$action}", "title" => "Methode introuvable"]))->display();
}
$controller->render($controller->view);
}
示例8: routes
/**
* Routes for this Members Module
*/
public function routes()
{
Router::any('members', 'Modules\\Members\\Controllers\\Members@members');
Router::any('online-members', 'Modules\\Members\\Controllers\\Members@online');
Router::any('profile/(:any)', 'Modules\\Members\\Controllers\\Members@viewProfile');
Router::any('edit-profile', 'Modules\\Members\\Controllers\\Members@editProfile');
}
示例9: run
public function run()
{
$sFieldName = $this->post('field_name');
$sFieldValue = $this->post('field_value');
$iAccountID = $this->post('account_id');
(new m\Account())->addField($sFieldName, $sFieldValue, $iAccountID);
c\Router::redirect(c\Router::genURL('Detail', ['id' => $iAccountID]));
}
示例10: run
public function run()
{
$sAccountName = $this->post('account_name');
$sAccountURL = 'http://' . parse_url($this->post('account_url'))['host'];
$iAccountID = $this->post('account_id');
(new m\Account())->updateAccount($sAccountName, parse_url($sAccountURL)['host'], $iAccountID, false);
c\Router::redirect(c\Router::genURL('Detail', ['id' => $iAccountID]));
}
示例11: run
public function run()
{
$sName = $this->post('name');
$sURL = $this->post('url');
$aURLDetail = parse_url($sURL);
$iAccountID = (new m\Account())->addAccount($sName, $aURLDetail['host']);
c\Router::redirect(c\Router::genURL('Detail', ['id' => $iAccountID]));
}
示例12: routes
public function routes()
{
Router::any('AdminPanel', 'Modules\\AdminPanel\\Controllers\\AdminPanel@dashboard');
Router::any('AdminPanel-Users', 'Modules\\AdminPanel\\Controllers\\AdminPanel@users');
Router::any('AdminPanel-User/(:any)', 'Modules\\AdminPanel\\Controllers\\AdminPanel@user');
Router::any('AdminPanel-Groups', 'Modules\\AdminPanel\\Controllers\\AdminPanel@groups');
Router::any('AdminPanel-Group/(:any)', 'Modules\\AdminPanel\\Controllers\\AdminPanel@group');
}
示例13: routes
public function routes()
{
Router::any('Profile/(:any)', 'Modules\\Profile\\Controllers\\Profile@viewprofile');
Router::any('Profile', 'Modules\\Profile\\Controllers\\Profile@viewprofile_error');
Router::any('Profile_Error', 'Modules\\Profile\\Controllers\\Profile@viewprofile_error');
Router::any('Profile_Error/(:any)', 'Modules\\Profile\\Controllers\\Profile@viewprofile_error');
Router::any('EditProfile', 'Modules\\Profile\\Controllers\\Profile@profile_edit');
Router::any('PrivacySettings', 'Modules\\Profile\\Controllers\\Profile@privacy_settings');
}
示例14: nested
public static function nested($class, $offset = 1)
{
if (!isset(\Core\Router::$uriParts[$offset])) {
return;
}
$next = \Core\Router::$uriParts[$offset];
$parts = array_slice(explode('\\', $class), 1);
$path = strtolower(implode(DIRECTORY_SEPARATOR, $parts));
\Core\Router::controller($path, $next);
}
示例15: run
public function run()
{
$oAccount = new m\Account();
$iTotal = $oAccount->getTotal();
if ($iTotal === false) {
$oAccount->createTable();
}
$aData = ['page_title' => 'Open Sesame', 'form_action_add' => c\Router::genURL('AddAccount'), 'site_total' => $iTotal, 'recomm' => (new m\Recommand())->get(4)];
return $aData;
}