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
eeed9c3f
Commit
eeed9c3f
authored
Oct 31, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #998: Added support for generating canonical URL.
parent
1c1cd863
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
2 deletions
+25
-2
Controller.php
framework/yii/web/Controller.php
+25
-2
No files found.
framework/yii/web/Controller.php
View file @
eeed9c3f
...
@@ -24,6 +24,10 @@ class Controller extends \yii\base\Controller
...
@@ -24,6 +24,10 @@ class Controller extends \yii\base\Controller
* CSRF validation is enabled only when both this property and [[Request::enableCsrfValidation]] are true.
* CSRF validation is enabled only when both this property and [[Request::enableCsrfValidation]] are true.
*/
*/
public
$enableCsrfValidation
=
true
;
public
$enableCsrfValidation
=
true
;
/**
* @var array the parameters bound to the current action. This is mainly used by [[getCanonicalUrl()]].
*/
public
$actionParams
=
[];
/**
/**
* Binds the parameters to the action.
* Binds the parameters to the action.
...
@@ -46,13 +50,14 @@ class Controller extends \yii\base\Controller
...
@@ -46,13 +50,14 @@ class Controller extends \yii\base\Controller
$args
=
[];
$args
=
[];
$missing
=
[];
$missing
=
[];
$actionParams
=
[];
foreach
(
$method
->
getParameters
()
as
$param
)
{
foreach
(
$method
->
getParameters
()
as
$param
)
{
$name
=
$param
->
getName
();
$name
=
$param
->
getName
();
if
(
array_key_exists
(
$name
,
$params
))
{
if
(
array_key_exists
(
$name
,
$params
))
{
$args
[]
=
$params
[
$name
];
$args
[]
=
$
actionParams
[
$name
]
=
$
params
[
$name
];
unset
(
$params
[
$name
]);
unset
(
$params
[
$name
]);
}
elseif
(
$param
->
isDefaultValueAvailable
())
{
}
elseif
(
$param
->
isDefaultValueAvailable
())
{
$args
[]
=
$param
->
getDefaultValue
();
$args
[]
=
$
actionParams
[
$name
]
=
$
param
->
getDefaultValue
();
}
else
{
}
else
{
$missing
[]
=
$name
;
$missing
[]
=
$name
;
}
}
...
@@ -64,6 +69,8 @@ class Controller extends \yii\base\Controller
...
@@ -64,6 +69,8 @@ class Controller extends \yii\base\Controller
]));
]));
}
}
$this
->
actionParams
=
$actionParams
;
return
$args
;
return
$args
;
}
}
...
@@ -113,6 +120,22 @@ class Controller extends \yii\base\Controller
...
@@ -113,6 +120,22 @@ class Controller extends \yii\base\Controller
}
}
/**
/**
* Returns the canonical URL of the currently requested page.
* The canonical URL is constructed using [[route]] and [[actionParams]]. You may use the following code
* in the layout view to add a link tag about canonical URL:
*
* ~~~
* $this->registerLinkTag(['rel' => 'canonical', 'href' => Yii::$app->controller->canonicalUrl]);
* ~~~
*
* @return string
*/
public
function
getCanonicalUrl
()
{
return
Yii
::
$app
->
getUrlManager
()
->
createAbsoluteUrl
(
$this
->
getRoute
(),
$this
->
actionParams
);
}
/**
* Redirects the browser to the specified URL.
* Redirects the browser to the specified URL.
* This method is a shortcut to [[Response::redirect()]].
* This method is a shortcut to [[Response::redirect()]].
*
*
...
...
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