本文整理汇总了PHP中Gdn::Router方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn::Router方法的具体用法?PHP Gdn::Router怎么用?PHP Gdn::Router使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn
的用法示例。
在下文中一共展示了Gdn::Router方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: AfterImport
public function AfterImport()
{
// Set up the routes to redirect from their older counterparts.
$Router = Gdn::Router();
// Categories
$Router->SetRoute('forumdisplay\\.php\\?f=(\\d+)', 'categories/$1', 'Permanent');
$Router->SetRoute('archive\\.php/f-(\\d+)\\.html', 'categories/$1', 'Permanent');
// Discussions & Comments
$Router->SetRoute('showthread\\.php\\?t=(\\d+)', 'discussion/$1', 'Permanent');
//$Router->SetRoute('showthread\.php\?p=(\d+)', 'discussion/comment/$1#Comment_$1', 'Permanent');
//$Router->SetRoute('showpost\.php\?p=(\d+)', 'discussion/comment/$1#Comment_$1', 'Permanent');
$Router->SetRoute('archive\\.php/t-(\\d+)\\.html', 'discussion/$1', 'Permanent');
// Profiles
$Router->SetRoute('member\\.php\\?u=(\\d+)', 'profile/$1/x', 'Permanent');
$Router->SetRoute('usercp\\.php', 'profile', 'Permanent');
$Router->SetRoute('profile\\.php', 'profile', 'Permanent');
// Other
$Router->SetRoute('attachment\\.php\\?attachmentid=(\\d+)', 'discussion/download/$1', 'Permanent');
$Router->SetRoute('search\\.php', 'discussions', 'Permanent');
$Router->SetRoute('private\\.php', 'messages/all', 'Permanent');
$Router->SetRoute('subscription\\.php', 'discussions/bookmarked', 'Permanent');
// Make different sizes of avatars
$this->ProcessAvatars();
// Prep config for ProfileExtender plugin based on imported fields
$this->ProfileExtenderPrep();
// Set guests to System user to prevent security issues
$SystemUserID = Gdn::UserModel()->GetSystemUserID();
$this->SQL->Update('Discussion')->Set('InsertUserID', $SystemUserID)->Where('InsertUserID', 0)->Put();
$this->SQL->Update('Comment')->Set('InsertUserID', $SystemUserID)->Where('InsertUserID', 0)->Put();
}
示例2: Gdn_Dispatcher_BeforeDispatch_Handler
public function Gdn_Dispatcher_BeforeDispatch_Handler($Sender)
{
$Request = Gdn::Request();
$RequestUri = $Request->RequestUri();
if (Gdn::Router()->GetRoute($RequestUri) === False) {
$RequestArgs = SplitUpString($RequestUri, '/', 'strtolower');
if (array_key_exists(0, $RequestArgs)) {
$ApplicationFolders = $Sender->EnabledApplicationFolders();
$bFoundApplication = in_array($RequestArgs[0], $ApplicationFolders);
if ($bFoundApplication === False) {
$PathParts = array('controllers', 'class.' . $RequestArgs[0] . 'controller.php');
$ControllerFileName = CombinePaths($PathParts);
$ControllerPath = Gdn_FileSystem::FindByMapping('controller', PATH_APPLICATIONS, $ApplicationFolders, $ControllerFileName);
if (!$ControllerPath || !file_exists($ControllerPath)) {
$Sender->EventArguments['RequestUri'] =& $RequestUri;
$Sender->FireEvent('BeforeGetRoute');
$NewRequest = CandyModel::GetRouteRequestUri($RequestUri);
if ($NewRequest) {
$Request->WithURI($NewRequest);
}
}
}
}
}
}
示例3: AfterImport
public function AfterImport()
{
// Set up the routes to redirect from their older counterparts.
$Router = Gdn::Router();
$Router->SetRoute('forumdisplay\\.php\\?f=(\\d+)', 'vanilla/categories/$1', 'Permanent');
$Router->SetRoute('showthread\\.php\\?t=(\\d+)', 'vanilla/discussion/$1', 'Permanent');
$Router->SetRoute('member\\.php\\?u=(\\d+)', 'dashboard/profile/$1/x', 'Permanent');
}
示例4: Setup
public function Setup()
{
$matchroute = '^members(/.*)?$';
$target = 'plugin/MembersListEnh$1';
if (!Gdn::Router()->MatchRoute($matchroute)) {
Gdn::Router()->SetRoute($matchroute, $target, 'Internal');
}
}
示例5: AfterImport
public function AfterImport() {
// Set up the routes to redirect from their older counterparts.
$Router = Gdn::Router();
$Router->SetRoute('forumdisplay\.php\?f=(\d+)', 'vanilla/categories/$1', 'Permanent');
$Router->SetRoute('showthread\.php\?t=(\d+)', 'vanilla/discussion/$1', 'Permanent');
$Router->SetRoute('member\.php\?u=(\d+)', 'dashboard/profile/$1/x', 'Permanent');
// Make different sizes of avatars
$this->ProcessAvatars();
}
示例6: AfterImport
public function AfterImport()
{
// Set up the routes to redirect from their older counterparts.
$Router = Gdn::Router();
$Router->SetRoute('\\?CategoryID=(\\d+)(?:&page=(\\d+))?', 'categories/$1/p$2', 'Permanent');
$Router->SetRoute('\\?page=(\\d+)', 'discussions/p$1', 'Permanent');
$Router->SetRoute('comments\\.php\\?DiscussionID=(\\d+)', 'discussion/$1/x', 'Permanent');
$Router->SetRoute('comments\\.php\\?DiscussionID=(\\d+)&page=(\\d+)', 'discussion/$1/x/p$2', 'Permanent');
$Router->SetRoute('account\\.php\\?u=(\\d+)', 'dashboard/profile/$1/x', 'Permanent');
}
示例7: Delete
public function Delete($RouteIndex = FALSE, $TransientKey = FALSE)
{
$this->Permission('Garden.Routes.Manage');
$this->DeliveryType(DELIVERY_TYPE_BOOL);
$Session = Gdn::Session();
// If seeing the form for the first time...
if ($TransientKey !== FALSE && $Session->ValidateTransientKey($TransientKey)) {
Gdn::Router()->DeleteRoute($RouteIndex);
}
if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
Redirect('dashboard/routes');
}
$this->Render();
}
示例8: Setup
public function Setup()
{
$OldFormat = C('Garden.InputFormatter');
if ($OldFormat != 'BBCode') {
SaveToConfig(array('Garden.InputFormatter' => 'BBCode', 'Garden.InputFormatterBak' => $OldFormat));
}
// Setup the default routes.
$Router = Gdn::Router();
$Router->SetRoute('\\?board=(\\d+).*$', 'categories/$1', 'Permanent');
$Router->SetRoute('index\\.php/topic,(\\d+).(\\d+)\\.html.*$', 'discussion/$1/x/$2lim', 'Permanent');
$Router->SetRoute('index\\.php/board,(\\d+)\\.(\\d+)\\.html.*$', 'categories/$1/$2lim', 'Permanent');
$Router->SetRoute('\\?action=profile%3Bu%3D(\\d+).*$', 'profile/$1/x', 'Permanent');
$Router->SetRoute('index\\.php/topic,(\\d+)\\.msg(\\d+)\\.html.*$', 'discussion/comment/$2/#Comment_$2', 'Permanent');
$Router->SetRoute('\\?topic=(\\d+).*$', 'discussion/$1/x/p1', 'Permanent');
}
示例9: AnalyzeRequest
/**
* Parses the query string looking for supplied request parameters. Places
* anything useful into this object's Controller properties.
*
* @param int $FolderDepth
*/
protected function AnalyzeRequest(&$Request)
{
// Here is the basic format of a request:
// [/application]/controller[/method[.json|.xml]]/argn|argn=valn
// Here are some examples of what this method could/would receive:
// /application/controller/method/argn
// /controller/method/argn
// /application/controller/argn
// /controller/argn
// /controller
// Clear the slate
$this->_ApplicationFolder = '';
$this->ControllerFolder = '';
$this->ControllerName = '';
$this->ControllerMethod = 'index';
$this->_ControllerMethodArgs = array();
$this->Request = $Request->Path(FALSE);
$PathAndQuery = $Request->PathAndQuery();
$MatchRoute = Gdn::Router()->MatchRoute($PathAndQuery);
// We have a route. Take action.
if ($MatchRoute !== FALSE) {
switch ($MatchRoute['Type']) {
case 'Internal':
$Request->PathAndQuery($MatchRoute['FinalDestination']);
$this->Request = $Request->Path(FALSE);
break;
case 'Temporary':
header("HTTP/1.1 302 Moved Temporarily");
header("Location: " . Url($MatchRoute['FinalDestination']));
exit;
break;
case 'Permanent':
header("HTTP/1.1 301 Moved Permanently");
header("Location: " . Url($MatchRoute['FinalDestination']));
exit;
break;
case 'NotAuthorized':
header("HTTP/1.1 401 Not Authorized");
$this->Request = $MatchRoute['FinalDestination'];
break;
case 'NotFound':
header("HTTP/1.1 404 Not Found");
$this->Request = $MatchRoute['FinalDestination'];
break;
case 'Test':
$Request->PathAndQuery($MatchRoute['FinalDestination']);
$this->Request = $Request->Path(FALSE);
decho($MatchRoute, 'Route');
decho(array('Path' => $Request->Path(), 'Get' => $Request->Get()), 'Request');
die;
}
}
switch ($Request->OutputFormat()) {
case 'rss':
$this->_SyndicationMethod = SYNDICATION_RSS;
break;
case 'atom':
$this->_SyndicationMethod = SYNDICATION_ATOM;
break;
case 'default':
default:
$this->_SyndicationMethod = SYNDICATION_NONE;
break;
}
if ($this->Request == '') {
$DefaultController = Gdn::Router()->GetRoute('DefaultController');
$this->Request = $DefaultController['Destination'];
}
$Parts = explode('/', str_replace('\\', '/', $this->Request));
/**
* The application folder is either the first argument or is not provided. The controller is therefore
* either the second argument or the first, depending on the result of the previous statement. Check that.
*/
try {
// if the 1st argument is a valid application, check if it has a controller matching the 2nd argument
if (in_array($Parts[0], $this->EnabledApplicationFolders())) {
$this->FindController(1, $Parts);
}
// if no match, see if the first argument is a controller
$this->FindController(0, $Parts);
// 3] See if there is a plugin trying to create a root method.
list($MethodName, $DeliveryMethod) = $this->_SplitDeliveryMethod(GetValue(0, $Parts), TRUE);
if ($MethodName && Gdn::PluginManager()->HasNewMethod('RootController', $MethodName, TRUE)) {
$this->_DeliveryMethod = $DeliveryMethod;
$Parts[0] = $MethodName;
$Parts = array_merge(array('root'), $Parts);
$this->FindController(0, $Parts);
}
throw new GdnDispatcherControllerNotFoundException();
} catch (GdnDispatcherControllerFoundException $e) {
switch ($this->_DeliveryMethod) {
case DELIVERY_METHOD_JSON:
case DELIVERY_METHOD_XML:
$this->_DeliveryType = DELIVERY_TYPE_DATA;
//.........这里部分代码省略.........
示例10: Index
/**
* Default all discussions view: chronological by most recent comment.
*
* @since 2.0.0
* @access public
*
* @param int $Page Multiplied by PerPage option to determine offset.
*/
public function Index($Page = FALSE)
{
// Figure out which discussions layout to choose (Defined on "Homepage" settings page).
$Layout = C('Vanilla.Discussions.Layout');
switch ($Layout) {
case 'table':
if ($this->SyndicationMethod == SYNDICATION_NONE) {
$this->View = 'table';
}
break;
default:
// $this->View = 'index';
break;
}
Gdn_Theme::Section('DiscussionList');
// Determine offset from $Page
list($Offset, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
$Page = PageNumber($Offset, $Limit);
// Allow page manipulation
$this->EventArguments['Page'] =& $Page;
$this->EventArguments['Offset'] =& $Offset;
$this->EventArguments['Limit'] =& $Limit;
$this->FireEvent('AfterPageCalculation');
// Set canonical URL
$this->CanonicalUrl(Url(ConcatSep('/', 'discussions', PageNumber($Offset, $Limit, TRUE, FALSE)), TRUE));
// We want to limit the number of pages on large databases because requesting a super-high page can kill the db.
$MaxPages = C('Vanilla.Discussions.MaxPages');
if ($MaxPages && $Page > $MaxPages) {
throw NotFoundException();
}
// Setup head.
if (!$this->Data('Title')) {
$Title = C('Garden.HomepageTitle');
$DefaultControllerRoute = val('Destination', Gdn::Router()->GetRoute('DefaultController'));
if ($Title && $DefaultControllerRoute == 'discussions') {
$this->Title($Title, '');
} else {
$this->Title(T('Recent Discussions'));
}
}
if (!$this->Description()) {
$this->Description(C('Garden.Description', NULL));
}
if ($this->Head) {
$this->Head->AddRss(Url('/discussions/feed.rss', TRUE), $this->Head->Title());
}
// Add modules
$this->AddModule('DiscussionFilterModule');
$this->AddModule('NewDiscussionModule');
$this->AddModule('CategoriesModule');
$this->AddModule('BookmarkedModule');
$this->SetData('Breadcrumbs', array(array('Name' => T('Recent Discussions'), 'Url' => '/discussions')));
// Set criteria & get discussions data
$this->SetData('Category', FALSE, TRUE);
$DiscussionModel = new DiscussionModel();
$DiscussionModel->Watching = TRUE;
// Get Discussion Count
$CountDiscussions = $DiscussionModel->GetCount();
if ($MaxPages) {
$CountDiscussions = min($MaxPages * $Limit, $CountDiscussions);
}
$this->SetData('CountDiscussions', $CountDiscussions);
// Get Announcements
$this->AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements() : FALSE;
$this->SetData('Announcements', $this->AnnounceData !== FALSE ? $this->AnnounceData : array(), TRUE);
// Get Discussions
$this->DiscussionData = $DiscussionModel->GetWhere(FALSE, $Offset, $Limit);
$this->SetData('Discussions', $this->DiscussionData, TRUE);
$this->SetJson('Loading', $Offset . ' to ' . $Limit);
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->EventArguments['PagerType'] = 'Pager';
$this->FireEvent('BeforeBuildPager');
$this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
$this->Pager->ClientID = 'Pager';
$this->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/%1$s');
if (!$this->Data('_PagerUrl')) {
$this->SetData('_PagerUrl', 'discussions/{Page}');
}
$this->SetData('_Page', $Page);
$this->SetData('_Limit', $Limit);
$this->FireEvent('AfterBuildPager');
// Deliver JSON data if necessary
if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
$this->SetJson('LessRow', $this->Pager->ToString('less'));
$this->SetJson('MoreRow', $this->Pager->ToString('more'));
$this->View = 'discussions';
}
$this->Render();
}
示例11: Structure
public function Structure()
{
Gdn::Router()->SetRoute('sitemapindex.xml', '/utility/sitemapindex.xml', 'Internal');
Gdn::Router()->SetRoute('sitemap-(.+)', '/utility/sitemap/$1', 'Internal');
Gdn::Router()->SetRoute('robots.txt', '/utility/robots', 'Internal');
}
示例12: WithRoute
public function WithRoute($Route)
{
$ParsedURI = Gdn::Router()->GetDestination($Route);
if ($ParsedURI) {
$this->_EnvironmentElement('URI', $ParsedURI);
}
return $this;
}
示例13: Homepage
/**
* Homepage management screen.
*
* @since 2.0.0
* @access public
*/
public function Homepage()
{
$this->Permission('Garden.Settings.Manage');
// Page setup
$this->AddSideMenu('dashboard/settings/homepage');
$this->Title(T('Homepage'));
$this->AddJsFile('homepage.js');
if (!$this->Form->AuthenticatedPostBack()) {
$this->Route = Gdn::Router()->GetRoute('DefaultController');
$this->Form->SetData(array('Target' => $this->Route['Destination']));
} else {
Gdn::Router()->DeleteRoute('DefaultController');
Gdn::Router()->SetRoute('DefaultController', ArrayValue('Target', $this->Form->FormValues()), 'Internal');
$this->InformMessage(T("The homepage was saved successfully."));
}
$this->Render();
}
示例14: array
<?php
echo $this->Form->Open();
echo $this->Form->Errors();
?>
<ul>
<li>
<?php
echo $this->Form->Label('Route Expression', 'Route');
$Attributes = array();
if ($this->Route['Reserved']) {
//$Attributes['value'] = $this->Route;
$Attributes['disabled'] = 'disabled';
}
echo $this->Form->TextBox('Route', $Attributes);
?>
</li>
<li>
<?php
echo $this->Form->Label('Target', 'Target');
echo $this->Form->TextBox('Target');
?>
</li>
<li>
<?php
echo $this->Form->Label('Type', 'Route Type');
echo $this->Form->DropDown('Type', Gdn::Router()->GetRouteTypes());
?>
</li>
</ul>
<?php
echo $this->Form->Close('Save');
示例15: AnalyzeRequest
/**
* Parses the query string looking for supplied request parameters. Places
* anything useful into this object's Controller properties.
*
* @param int $FolderDepth
*/
protected function AnalyzeRequest(&$Request) {
// Here is the basic format of a request:
// [/application]/controller[/method[.json|.xml]]/argn|argn=valn
// Here are some examples of what this method could/would receive:
// /application/controller/method/argn
// /controller/method/argn
// /application/controller/argn
// /controller/argn
// /controller
// Clear the slate
$this->_ApplicationFolder = '';
$this->_ControllerFolder = '';
$this->_ControllerName = '';
$this->_ControllerMethod = 'index';
$this->_ControllerMethodArgs = array();
$this->Request = $Request->Path(FALSE);
$PathAndQuery = $Request->PathAndQuery();
$MatchRoute = Gdn::Router()->MatchRoute($PathAndQuery);
// We have a route. Take action.
if ($MatchRoute !== FALSE) {
switch ($MatchRoute['Type']) {
case 'Internal':
$Request->PathAndQuery($MatchRoute['FinalDestination']);
$this->Request = $Request->Path(FALSE);
break;
case 'Temporary':
header("HTTP/1.1 302 Moved Temporarily" );
header("Location: ".Url($MatchRoute['FinalDestination']));
exit();
break;
case 'Permanent':
header("HTTP/1.1 301 Moved Permanently" );
header("Location: ".Url($MatchRoute['FinalDestination']));
exit();
break;
case 'NotAuthorized':
header("HTTP/1.1 401 Not Authorized" );
$this->Request = $MatchRoute['FinalDestination'];
break;
case 'NotFound':
header("HTTP/1.1 404 Not Found" );
$this->Request = $MatchRoute['FinalDestination'];
break;
}
}
switch ($Request->OutputFormat()) {
case 'rss':
$this->_SyndicationMethod = SYNDICATION_RSS;
break;
case 'atom':
$this->_SyndicationMethod = SYNDICATION_ATOM;
break;
case 'default':
default:
$this->_SyndicationMethod = SYNDICATION_NONE;
break;
}
if ($this->Request == '') {
$DefaultController = Gdn::Router()->GetRoute('DefaultController');
$this->Request = $DefaultController['Destination'];
}
$Parts = explode('/', str_replace('\\', '/', $this->Request));
/**
* The application folder is either the first argument or is not provided. The controller is therefore
* either the second argument or the first, depending on the result of the previous statement. Check that.
*/
try {
// 1] if the 1st argument is a valid application, check if it has a controller matching the 2nd argument
if (in_array($Parts[0], $this->EnabledApplicationFolders()))
$this->FindController(1, $Parts);
// 2] if no match, see if the first argument is a controller
$this->FindController(0, $Parts);
throw new GdnDispatcherControllerNotFoundException();
} catch (GdnDispatcherControllerFoundException $e) {
// Success!
//.........这里部分代码省略.........