Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
0093d534
Commit
0093d534
authored
Feb 19, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
url wip
parent
c08c2e8b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
22 deletions
+68
-22
UrlManager.php
framework/web/UrlManager.php
+68
-22
No files found.
framework/web/UrlManager.php
View file @
0093d534
...
@@ -67,28 +67,33 @@ class UrlManager extends Component
...
@@ -67,28 +67,33 @@ class UrlManager extends Component
parent
::
init
();
parent
::
init
();
if
(
$this
->
enablePrettyUrl
&&
$this
->
rules
!==
array
())
{
if
(
$this
->
enablePrettyUrl
&&
$this
->
rules
!==
array
())
{
/**
$this
->
compileRules
();
* @var $cache \yii\caching\Cache
}
*/
}
if
(
$this
->
cacheID
!==
false
&&
(
$cache
=
Yii
::
$app
->
getComponent
(
$this
->
cacheID
))
!==
null
)
{
$key
=
$cache
->
buildKey
(
__CLASS__
);
$hash
=
md5
(
json_encode
(
$this
->
rules
));
if
((
$data
=
$cache
->
get
(
$key
))
!==
false
&&
isset
(
$data
[
1
])
&&
$data
[
1
]
===
$hash
)
{
$this
->
rules
=
$data
[
0
];
return
;
}
}
foreach
(
$this
->
rules
as
$i
=>
$rule
)
{
protected
function
compileRules
()
if
(
!
isset
(
$rule
[
'class'
]))
{
{
$rule
[
'class'
]
=
$this
->
defaultRuleClass
;
/**
}
* @var $cache \yii\caching\Cache
$this
->
rules
[
$i
]
=
Yii
::
createObject
(
$rule
);
*/
if
(
$this
->
cacheID
!==
false
&&
(
$cache
=
Yii
::
$app
->
getComponent
(
$this
->
cacheID
))
!==
null
)
{
$key
=
$cache
->
buildKey
(
__CLASS__
);
$hash
=
md5
(
json_encode
(
$this
->
rules
));
if
((
$data
=
$cache
->
get
(
$key
))
!==
false
&&
isset
(
$data
[
1
])
&&
$data
[
1
]
===
$hash
)
{
$this
->
rules
=
$data
[
0
];
return
;
}
}
}
if
(
isset
(
$cache
))
{
foreach
(
$this
->
rules
as
$i
=>
$rule
)
{
$cache
->
set
(
$key
,
array
(
$this
->
rules
,
$hash
));
if
(
!
isset
(
$rule
[
'class'
]))
{
$rule
[
'class'
]
=
$this
->
defaultRuleClass
;
}
}
$this
->
rules
[
$i
]
=
Yii
::
createObject
(
$rule
);
}
if
(
isset
(
$cache
))
{
$cache
->
set
(
$key
,
array
(
$this
->
rules
,
$hash
));
}
}
}
}
...
@@ -98,7 +103,7 @@ class UrlManager extends Component
...
@@ -98,7 +103,7 @@ class UrlManager extends Component
* @return array|boolean the route and the associated parameters. The latter is always empty
* @return array|boolean the route and the associated parameters. The latter is always empty
* if [[enablePrettyUrl]] is false. False is returned if the current request cannot be successfully parsed.
* if [[enablePrettyUrl]] is false. False is returned if the current request cannot be successfully parsed.
*/
*/
public
function
parse
Url
(
$request
)
public
function
parse
Request
(
$request
)
{
{
if
(
$this
->
enablePrettyUrl
)
{
if
(
$this
->
enablePrettyUrl
)
{
$pathInfo
=
$request
->
pathInfo
;
$pathInfo
=
$request
->
pathInfo
;
...
@@ -135,11 +140,13 @@ class UrlManager extends Component
...
@@ -135,11 +140,13 @@ class UrlManager extends Component
$route
=
trim
(
$route
,
'/'
);
$route
=
trim
(
$route
,
'/'
);
$baseUrl
=
$this
->
getBaseUrl
();
if
(
$this
->
enablePrettyUrl
)
{
if
(
$this
->
enablePrettyUrl
)
{
/** @var $rule UrlRule */
/** @var $rule UrlRule */
foreach
(
$this
->
rules
as
$rule
)
{
foreach
(
$this
->
rules
as
$rule
)
{
if
((
$url
=
$rule
->
createUrl
(
$this
,
$route
,
$params
))
!==
false
)
{
if
((
$url
=
$rule
->
createUrl
(
$this
,
$route
,
$params
))
!==
false
)
{
return
$
this
->
getBaseUrl
()
.
$url
.
$anchor
;
return
$
baseUrl
.
$url
.
$anchor
;
}
}
}
}
...
@@ -149,17 +156,39 @@ class UrlManager extends Component
...
@@ -149,17 +156,39 @@ class UrlManager extends Component
if
(
$params
!==
array
())
{
if
(
$params
!==
array
())
{
$route
.=
'?'
.
http_build_query
(
$params
);
$route
.=
'?'
.
http_build_query
(
$params
);
}
}
return
$
this
->
getBaseUrl
()
.
'/'
.
$route
.
$anchor
;
return
$
baseUrl
.
'/'
.
$route
.
$anchor
;
}
else
{
}
else
{
$params
[
$this
->
routeVar
]
=
$route
;
$params
[
$this
->
routeVar
]
=
$route
;
return
$this
->
getBaseUrl
()
.
'?'
.
http_build_query
(
$params
)
.
$anchor
;
if
(
!
$this
->
showScriptName
)
{
$baseUrl
.=
'/'
;
}
return
$baseUrl
.
'?'
.
http_build_query
(
$params
)
.
$anchor
;
}
}
}
}
public
function
createAbsoluteUrl
(
$route
,
$params
=
array
(),
$hostInfo
=
null
)
{
if
(
$hostInfo
===
null
)
{
$hostInfo
=
$this
->
getHostInfo
();
}
return
$hostInfo
.
$this
->
createUrl
(
$route
,
$params
);
}
private
$_baseUrl
;
private
$_baseUrl
;
/**
* Returns the base URL of the application.
* @return string the base URL of the application (the part after host name and before query string).
* If {@link showScriptName} is true, it will include the script name part.
* Otherwise, it will not, and the ending slashes are stripped off.
*/
public
function
getBaseUrl
()
public
function
getBaseUrl
()
{
{
if
(
$this
->
_baseUrl
===
null
)
{
/** @var $request \yii\web\Request */
$request
=
Yii
::
$app
->
getRequest
();
$this
->
_baseUrl
=
$this
->
showScriptName
?
$request
->
getScriptUrl
()
:
$request
->
getBaseUrl
();
}
return
$this
->
_baseUrl
;
return
$this
->
_baseUrl
;
}
}
...
@@ -168,6 +197,23 @@ class UrlManager extends Component
...
@@ -168,6 +197,23 @@ class UrlManager extends Component
$this
->
_baseUrl
=
trim
(
$value
,
'/'
);
$this
->
_baseUrl
=
trim
(
$value
,
'/'
);
}
}
private
$_hostInfo
;
public
function
getHostInfo
()
{
if
(
$this
->
_hostInfo
===
null
)
{
/** @var $request \yii\web\Request */
$request
=
Yii
::
$app
->
getRequest
();
$this
->
_hostInfo
=
$request
->
getHostInfo
();
}
return
$this
->
_baseUrl
;
}
public
function
setHostInfo
(
$value
)
{
$this
->
_hostInfo
=
$value
;
}
/**
/**
* Removes the URL suffix from path info.
* Removes the URL suffix from path info.
* @param string $pathInfo path info part in the URL
* @param string $pathInfo path info part in the URL
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment