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
27ad7e1f
Commit
27ad7e1f
authored
Aug 12, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Controller::goHome().
parent
89fa7ed3
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
47 additions
and
18 deletions
+47
-18
SiteController.php
apps/advanced/backend/controllers/SiteController.php
+2
-2
SiteController.php
apps/advanced/frontend/controllers/SiteController.php
+5
-5
SiteController.php
apps/basic/controllers/SiteController.php
+2
-2
main.php
apps/basic/views/layouts/main.php
+2
-1
Controller.php
framework/yii/web/Controller.php
+20
-4
Response.php
framework/yii/web/Response.php
+16
-4
No files found.
apps/advanced/backend/controllers/SiteController.php
View file @
27ad7e1f
...
...
@@ -17,7 +17,7 @@ class SiteController extends Controller
{
$model
=
new
LoginForm
();
if
(
$model
->
load
(
$_POST
)
&&
$model
->
login
())
{
return
$this
->
redirect
(
array
(
'site/index'
)
);
return
$this
->
goHome
(
);
}
else
{
return
$this
->
render
(
'login'
,
array
(
'model'
=>
$model
,
...
...
@@ -28,6 +28,6 @@ class SiteController extends Controller
public
function
actionLogout
()
{
Yii
::
$app
->
user
->
logout
();
return
$this
->
redirect
(
array
(
'site/index'
)
);
return
$this
->
goHome
(
);
}
}
apps/advanced/frontend/controllers/SiteController.php
View file @
27ad7e1f
...
...
@@ -30,7 +30,7 @@ class SiteController extends Controller
{
$model
=
new
LoginForm
();
if
(
$model
->
load
(
$_POST
)
&&
$model
->
login
())
{
return
$this
->
redirect
(
array
(
'site/index'
)
);
return
$this
->
goHome
(
);
}
else
{
return
$this
->
render
(
'login'
,
array
(
'model'
=>
$model
,
...
...
@@ -41,7 +41,7 @@ class SiteController extends Controller
public
function
actionLogout
()
{
Yii
::
$app
->
user
->
logout
();
return
$this
->
redirect
(
array
(
'site/index'
)
);
return
$this
->
goHome
(
);
}
public
function
actionContact
()
...
...
@@ -68,7 +68,7 @@ class SiteController extends Controller
$model
->
setScenario
(
'signup'
);
if
(
$model
->
load
(
$_POST
)
&&
$model
->
save
())
{
if
(
Yii
::
$app
->
getUser
()
->
login
(
$model
))
{
$this
->
redirect
(
'index'
);
return
$this
->
goHome
(
);
}
}
...
...
@@ -84,7 +84,7 @@ class SiteController extends Controller
if
(
$model
->
load
(
$_POST
)
&&
$model
->
validate
())
{
if
(
$this
->
sendPasswordResetEmail
(
$model
->
email
))
{
Yii
::
$app
->
getSession
()
->
setFlash
(
'success'
,
'Check your email for further instructions.'
);
$this
->
redirect
(
'index'
);
return
$this
->
goHome
(
);
}
else
{
Yii
::
$app
->
getSession
()
->
setFlash
(
'error'
,
'There was an error sending email.'
);
}
...
...
@@ -108,7 +108,7 @@ class SiteController extends Controller
$model
->
scenario
=
'resetPassword'
;
if
(
$model
->
load
(
$_POST
)
&&
$model
->
save
())
{
Yii
::
$app
->
getSession
()
->
setFlash
(
'success'
,
'New password was saved.'
);
$this
->
redirect
(
'index'
);
return
$this
->
goHome
(
);
}
return
$this
->
render
(
'resetPassword'
,
array
(
...
...
apps/basic/controllers/SiteController.php
View file @
27ad7e1f
...
...
@@ -31,7 +31,7 @@ class SiteController extends Controller
{
$model
=
new
LoginForm
();
if
(
$model
->
load
(
$_POST
)
&&
$model
->
login
())
{
return
$this
->
redirect
(
array
(
'site/index'
)
);
return
$this
->
goHome
(
);
}
else
{
return
$this
->
render
(
'login'
,
array
(
'model'
=>
$model
,
...
...
@@ -42,7 +42,7 @@ class SiteController extends Controller
public
function
actionLogout
()
{
Yii
::
$app
->
user
->
logout
();
return
$this
->
redirect
(
array
(
'site/index'
)
);
return
$this
->
goHome
(
);
}
public
function
actionContact
()
...
...
apps/basic/views/layouts/main.php
View file @
27ad7e1f
...
...
@@ -37,7 +37,8 @@ app\config\AppAsset::register($this);
Yii
::
$app
->
user
->
isGuest
?
array
(
'label'
=>
'Login'
,
'url'
=>
array
(
'/site/login'
))
:
array
(
'label'
=>
'Logout ('
.
Yii
::
$app
->
user
->
identity
->
username
.
')'
,
'url'
=>
array
(
'/site/logout'
)),
)));
),
));
NavBar
::
end
();
?>
...
...
framework/yii/web/Controller.php
View file @
27ad7e1f
...
...
@@ -96,14 +96,21 @@ class Controller extends \yii\base\Controller
* Redirects the browser to the specified URL.
* This method is a shortcut to [[Response::redirect()]].
*
* @param array|string $url the URL to be redirected to. [[Html::url()]]
* will be used to normalize the URL. If the resulting URL is still a relative URL
* (one without host info), the current request host info will be used.
* @param string|array $url the URL to be redirected to. This can be in one of the following formats:
*
* - a string representing a URL (e.g. "http://example.com")
* - a string representing a URL alias (e.g. "@example.com")
* - an array in the format of `array($route, ...name-value pairs...)` (e.g. `array('site/index', 'ref' => 1)`)
* [[Html::url()]] will be used to convert the array into a URL.
*
* Any relative URL will be converted into an absolute one by prepending it with the host info
* of the current request.
*
* @param integer $statusCode the HTTP status code. If null, it will use 302
* for normal requests, and [[ajaxRedirectCode]] for AJAX requests.
* See [[http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html]]
* for details about HTTP status code
* @return Response the
response object itself
* @return Response the
current response object
*/
public
function
redirect
(
$url
,
$statusCode
=
null
)
{
...
...
@@ -111,6 +118,15 @@ class Controller extends \yii\base\Controller
}
/**
* Redirects the browser to the home page.
* @return Response the current response object
*/
public
function
goHome
()
{
return
Yii
::
$app
->
getResponse
()
->
redirect
(
Yii
::
$app
->
getHomeUrl
());
}
/**
* Refreshes the current page.
* This method is a shortcut to [[Response::refresh()]].
* @param string $anchor the anchor that should be appended to the redirection URL.
...
...
framework/yii/web/Response.php
View file @
27ad7e1f
...
...
@@ -563,9 +563,17 @@ class Response extends \yii\base\Response
* return Yii::$app->getResponse()->redirect($url);
* ~~~
*
* @param string $url the URL to be redirected to. This can be a URL or an alias of the URL.
* The URL can be either relative or absolute. If relative, the host info of the current request
* will be prepend to the URL.
* @param string|array $url the URL to be redirected to. This can be in one of the following formats:
*
* - a string representing a URL (e.g. "http://example.com")
* - a string representing a URL alias (e.g. "@example.com")
* - an array in the format of `array($route, ...name-value pairs...)` (e.g. `array('site/index', 'ref' => 1)`).
* Note that the route is with respect to the whole application, instead of relative to a controller or module.
* [[Html::url()]] will be used to convert the array into a URL.
*
* Any relative URL will be converted into an absolute one by prepending it with the host info
* of the current request.
*
* @param integer $statusCode the HTTP status code. If null, it will use 302
* for normal requests, and [[ajaxRedirectCode]] for AJAX requests.
* See [[http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html]]
...
...
@@ -574,7 +582,11 @@ class Response extends \yii\base\Response
*/
public
function
redirect
(
$url
,
$statusCode
=
null
)
{
$url
=
Yii
::
getAlias
(
$url
);
if
(
is_array
(
$url
)
&&
isset
(
$url
[
0
]))
{
// ensure the route is absolute
$url
[
0
]
=
'/'
.
ltrim
(
$url
[
0
],
'/'
);
}
$url
=
Html
::
url
(
$url
);
if
(
strpos
(
$url
,
'/'
)
===
0
&&
strpos
(
$url
,
'//'
)
!==
0
)
{
$url
=
Yii
::
$app
->
getRequest
()
->
getHostInfo
()
.
$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