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
cd1b3d32
Commit
cd1b3d32
authored
Mar 26, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored url creation shortcut method.
parent
8724d803
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
116 deletions
+41
-116
Application.php
framework/base/Application.php
+2
-2
Html.php
framework/helpers/Html.php
+10
-5
Application.php
framework/web/Application.php
+0
-45
Controller.php
framework/web/Controller.php
+26
-0
HttpCache.php
framework/web/HttpCache.php
+3
-5
User.php
framework/web/User.php
+0
-59
No files found.
framework/base/Application.php
View file @
cd1b3d32
...
...
@@ -78,7 +78,7 @@ class Application extends Module
*/
public
$preload
=
array
();
/**
* @var Controller the currently active controller instance
* @var
\yii\web\Controller|\yii\console\
Controller the currently active controller instance
*/
public
$controller
;
/**
...
...
@@ -355,7 +355,7 @@ class Application extends Module
/**
* Returns the request component.
* @return Request the request component
* @return
\yii\web\Request|\yii\console\
Request the request component
*/
public
function
getRequest
()
{
...
...
framework/helpers/Html.php
View file @
cd1b3d32
...
...
@@ -949,11 +949,10 @@ class Html
* If the input parameter
*
* - is an empty string: the currently requested URL will be returned;
* - is a non-empty string: it will be processed by [[Yii::getAlias()]] which, if the string is an alias,
* will be resolved into a URL;
* - is a non-empty string: it will be processed by [[Yii::getAlias()]] and returned;
* - is an array: the first array element is considered a route, while the rest of the name-value
* pairs are
considered as the parameters to be used for URL creation using [[\yii\base\Application
::createUrl()]].
*
Here are some examples
: `array('post/index', 'page' => 2)`, `array('index')`.
* pairs are
treated as the parameters to be used for URL creation using [[\yii\web\Controller
::createUrl()]].
*
For example
: `array('post/index', 'page' => 2)`, `array('index')`.
*
* @param array|string $url the parameter to be used to generate a valid URL
* @return string the normalized URL
...
...
@@ -963,7 +962,13 @@ class Html
{
if
(
is_array
(
$url
))
{
if
(
isset
(
$url
[
0
]))
{
return
Yii
::
$app
->
createUrl
(
$url
[
0
],
array_splice
(
$url
,
1
));
$route
=
$url
[
0
];
$params
=
array_splice
(
$url
,
1
);
if
(
Yii
::
$app
->
controller
!==
null
)
{
return
Yii
::
$app
->
controller
->
createUrl
(
$route
,
$params
);
}
else
{
return
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$route
,
$params
);
}
}
else
{
throw
new
InvalidParamException
(
'The array specifying a URL must contain at least one element.'
);
}
...
...
framework/web/Application.php
View file @
cd1b3d32
...
...
@@ -78,51 +78,6 @@ class Application extends \yii\base\Application
}
/**
* Creates a URL using the given route and parameters.
*
* This method first normalizes the given route by converting a relative route into an absolute one.
* A relative route is a route without a leading slash. It is considered to be relative to the currently
* requested route. If the route is an empty string, it stands for the route of the currently active
* [[controller]]. Otherwise, the [[Controller::uniqueId]] will be prepended to the route.
*
* After normalizing the route, this method calls [[\yii\web\UrlManager::createUrl()]]
* to create a relative URL.
*
* @param string $route the route. This can be either an absolute or a relative route.
* @param array $params the parameters (name-value pairs) to be included in the generated URL
* @return string the created URL
* @throws InvalidParamException if a relative route is given and there is no active controller.
* @see createAbsoluteUrl
*/
public
function
createUrl
(
$route
,
$params
=
array
())
{
if
(
strncmp
(
$route
,
'/'
,
1
)
!==
0
)
{
// a relative route
if
(
$this
->
controller
!==
null
)
{
$route
=
$route
===
''
?
$this
->
controller
->
route
:
$this
->
controller
->
uniqueId
.
'/'
.
$route
;
}
else
{
throw
new
InvalidParamException
(
'Relative route cannot be handled because there is no active controller.'
);
}
}
return
$this
->
getUrlManager
()
->
createUrl
(
$route
,
$params
);
}
/**
* Creates an absolute URL using the given route and parameters.
* This method first calls [[createUrl()]] to create a relative URL.
* It then prepends [[\yii\web\UrlManager::hostInfo]] to the URL to form an absolute one.
* @param string $route the route. This can be either an absolute or a relative route.
* See [[createUrl()]] for more details.
* @param array $params the parameters (name-value pairs)
* @return string the created URL
* @see createUrl
*/
public
function
createAbsoluteUrl
(
$route
,
$params
=
array
())
{
return
$this
->
getUrlManager
()
->
getHostInfo
()
.
$this
->
createUrl
(
$route
,
$params
);
}
/**
* Registers the core application components.
* @see setComponents
*/
...
...
framework/web/Controller.php
View file @
cd1b3d32
...
...
@@ -7,6 +7,8 @@
namespace
yii\web
;
use
Yii
;
/**
* Controller is the base class of Web controllers.
*
...
...
@@ -16,4 +18,27 @@ namespace yii\web;
*/
class
Controller
extends
\yii\base\Controller
{
/**
* Creates a URL using the given route and parameters.
*
* This method enhances [[UrlManager::createUrl()]] by supporting relative routes.
* A relative route is a route without a slash, such as "view". If the route is an empty
* string, [[route]] will be used; Otherwise, [[uniqueId]] will be prepended to a relative route.
*
* After this route conversion, the method This method calls [[UrlManager::createUrl()]]
* to create a URL.
*
* @param string $route the route. This can be either an absolute route or a relative route.
* @param array $params the parameters (name-value pairs) to be included in the generated URL
* @return string the created URL
*/
public
function
createUrl
(
$route
,
$params
=
array
())
{
if
(
strpos
(
$route
,
'/'
)
===
false
)
{
// a relative route
$route
=
$route
===
''
?
$this
->
getRoute
()
:
$this
->
getUniqueId
()
.
'/'
.
$route
;
}
return
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$route
,
$params
);
}
}
\ No newline at end of file
framework/web/HttpCache.php
View file @
cd1b3d32
...
...
@@ -84,12 +84,10 @@ class HttpCache extends ActionFilter
if
(
$this
->
validateCache
(
$lastModified
,
$etag
))
{
header
(
'HTTP/1.1 304 Not Modified'
);
return
false
;
}
else
{
if
(
$lastModified
!==
null
)
{
header
(
'Last-Modified: '
.
gmdate
(
'D, d M Y H:i:s'
,
$lastModified
)
.
' GMT'
);
}
return
true
;
}
elseif
(
$lastModified
!==
null
)
{
header
(
'Last-Modified: '
.
gmdate
(
'D, d M Y H:i:s'
,
$lastModified
)
.
' GMT'
);
}
return
true
;
}
/**
...
...
framework/web/User.php
View file @
cd1b3d32
...
...
@@ -126,65 +126,6 @@ class User extends Component
private
$_keyPrefix
;
private
$_access
=
array
();
/**
* PHP magic method.
* This method is overriden so that persistent states can be accessed like properties.
* @param string $name property name
* @return mixed property value
*/
public
function
__get
(
$name
)
{
if
(
$this
->
hasState
(
$name
))
{
return
$this
->
getState
(
$name
);
}
else
{
return
parent
::
__get
(
$name
);
}
}
/**
* PHP magic method.
* This method is overriden so that persistent states can be set like properties.
* @param string $name property name
* @param mixed $value property value
*/
public
function
__set
(
$name
,
$value
)
{
if
(
$this
->
hasState
(
$name
))
{
$this
->
setState
(
$name
,
$value
);
}
else
{
parent
::
__set
(
$name
,
$value
);
}
}
/**
* PHP magic method.
* This method is overriden so that persistent states can also be checked for null value.
* @param string $name property name
* @return boolean
*/
public
function
__isset
(
$name
)
{
if
(
$this
->
hasState
(
$name
))
{
return
$this
->
getState
(
$name
)
!==
null
;
}
else
{
return
parent
::
__isset
(
$name
);
}
}
/**
* PHP magic method.
* This method is overriden so that persistent states can also be unset.
* @param string $name property name
* @throws CException if the property is read only.
*/
public
function
__unset
(
$name
)
{
if
(
$this
->
hasState
(
$name
))
{
$this
->
setState
(
$name
,
null
);
}
else
{
parent
::
__unset
(
$name
);
}
}
/**
* Initializes the application component.
...
...
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