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
6f3d27fc
Commit
6f3d27fc
authored
Mar 11, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More examples for URL guide
parent
38e8afa0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
10 deletions
+36
-10
url.md
docs/guide/url.md
+36
-10
No files found.
docs/guide/url.md
View file @
6f3d27fc
...
...
@@ -51,23 +51,49 @@ examples may also output:
*
`http://www.example.com/blog/post/index/`
*
`http://www.example.com/index.php?r=blog/post/index`
In order to simplify URL creation there is
[
[yii\helpers\Url
]
] helper that is able to do the following:
In order to simplify URL creation there is
[
[yii\helpers\Url
]
] helper. Assuming we're at
`/index.php?r=management/default/users&id=10`
the following
is how
`Url`
helper works:
```
php
use
yii\helpers\Url
;
echo
Url
::
to
(
''
);
// currently active URL
// currently active route
// /index.php?r=management/default/users
echo
Url
::
to
(
''
);
echo
Url
::
toRoute
([
'view'
,
'id'
=>
'contact'
]);
// same controller, different action
echo
Url
::
toRoute
(
'post/index'
);
// same module, different controller and action
echo
Url
::
toRoute
(
'/site/index'
);
// absolute route no matter what controller is making this call
echo
Url
::
toRoute
(
'hi-tech'
);
// url for the case sensitive action `actionHiTech` of the current controller
echo
Url
::
toRoute
([
'/date-time/fast-forward'
,
'id'
=>
105
]);
// url for action the case sensitive controller, `DateTimeController::actionFastForward`
// same controller, different action
// /index.php?r=management/default/view&id=contact
echo
Url
::
toRoute
([
'page'
,
'id'
=>
'contact'
]);
echo
Url
::
to
(
'@web'
);
// get URL from alias
echo
Url
::
canonical
();
// get canonical URL for the curent page
echo
Url
::
home
();
// get home URL
// same module, different controller and action
// /index.php?r=management/post/index
echo
Url
::
toRoute
(
'post/index'
);
// absolute route no matter what controller is making this call
// /index.php?r=site/index
echo
Url
::
toRoute
(
'/site/index'
);
// url for the case sensitive action `actionHiTech` of the current controller
// /index.php?r=management/default/hi-tech
echo
Url
::
toRoute
(
'hi-tech'
);
// url for action the case sensitive controller, `DateTimeController::actionFastForward`
// /index.php?r=date-time/fast-forward&id=105
echo
Url
::
toRoute
([
'/date-time/fast-forward'
,
'id'
=>
105
]);
// get URL from alias
// http://google.com/
Yii
::
setAlias
(
'@google'
,
'http://google.com/'
);
echo
Url
::
to
(
'@google'
);
// get canonical URL for the curent page
// /index.php?r=management/default/users
echo
Url
::
canonical
();
// get home URL
// /index.php?r=site/index
echo
Url
::
home
();
Url
::
remember
();
// save URL to be used later
Url
::
previous
();
// get previously saved 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