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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
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
...
@@ -17,7 +17,7 @@ class SiteController extends Controller
{
{
$model
=
new
LoginForm
();
$model
=
new
LoginForm
();
if
(
$model
->
load
(
$_POST
)
&&
$model
->
login
())
{
if
(
$model
->
load
(
$_POST
)
&&
$model
->
login
())
{
return
$this
->
redirect
(
array
(
'site/index'
)
);
return
$this
->
goHome
(
);
}
else
{
}
else
{
return
$this
->
render
(
'login'
,
array
(
return
$this
->
render
(
'login'
,
array
(
'model'
=>
$model
,
'model'
=>
$model
,
...
@@ -28,6 +28,6 @@ class SiteController extends Controller
...
@@ -28,6 +28,6 @@ class SiteController extends Controller
public
function
actionLogout
()
public
function
actionLogout
()
{
{
Yii
::
$app
->
user
->
logout
();
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
...
@@ -30,7 +30,7 @@ class SiteController extends Controller
{
{
$model
=
new
LoginForm
();
$model
=
new
LoginForm
();
if
(
$model
->
load
(
$_POST
)
&&
$model
->
login
())
{
if
(
$model
->
load
(
$_POST
)
&&
$model
->
login
())
{
return
$this
->
redirect
(
array
(
'site/index'
)
);
return
$this
->
goHome
(
);
}
else
{
}
else
{
return
$this
->
render
(
'login'
,
array
(
return
$this
->
render
(
'login'
,
array
(
'model'
=>
$model
,
'model'
=>
$model
,
...
@@ -41,7 +41,7 @@ class SiteController extends Controller
...
@@ -41,7 +41,7 @@ class SiteController extends Controller
public
function
actionLogout
()
public
function
actionLogout
()
{
{
Yii
::
$app
->
user
->
logout
();
Yii
::
$app
->
user
->
logout
();
return
$this
->
redirect
(
array
(
'site/index'
)
);
return
$this
->
goHome
(
);
}
}
public
function
actionContact
()
public
function
actionContact
()
...
@@ -68,7 +68,7 @@ class SiteController extends Controller
...
@@ -68,7 +68,7 @@ class SiteController extends Controller
$model
->
setScenario
(
'signup'
);
$model
->
setScenario
(
'signup'
);
if
(
$model
->
load
(
$_POST
)
&&
$model
->
save
())
{
if
(
$model
->
load
(
$_POST
)
&&
$model
->
save
())
{
if
(
Yii
::
$app
->
getUser
()
->
login
(
$model
))
{
if
(
Yii
::
$app
->
getUser
()
->
login
(
$model
))
{
$this
->
redirect
(
'index'
);
return
$this
->
goHome
(
);
}
}
}
}
...
@@ -84,7 +84,7 @@ class SiteController extends Controller
...
@@ -84,7 +84,7 @@ class SiteController extends Controller
if
(
$model
->
load
(
$_POST
)
&&
$model
->
validate
())
{
if
(
$model
->
load
(
$_POST
)
&&
$model
->
validate
())
{
if
(
$this
->
sendPasswordResetEmail
(
$model
->
email
))
{
if
(
$this
->
sendPasswordResetEmail
(
$model
->
email
))
{
Yii
::
$app
->
getSession
()
->
setFlash
(
'success'
,
'Check your email for further instructions.'
);
Yii
::
$app
->
getSession
()
->
setFlash
(
'success'
,
'Check your email for further instructions.'
);
$this
->
redirect
(
'index'
);
return
$this
->
goHome
(
);
}
else
{
}
else
{
Yii
::
$app
->
getSession
()
->
setFlash
(
'error'
,
'There was an error sending email.'
);
Yii
::
$app
->
getSession
()
->
setFlash
(
'error'
,
'There was an error sending email.'
);
}
}
...
@@ -108,7 +108,7 @@ class SiteController extends Controller
...
@@ -108,7 +108,7 @@ class SiteController extends Controller
$model
->
scenario
=
'resetPassword'
;
$model
->
scenario
=
'resetPassword'
;
if
(
$model
->
load
(
$_POST
)
&&
$model
->
save
())
{
if
(
$model
->
load
(
$_POST
)
&&
$model
->
save
())
{
Yii
::
$app
->
getSession
()
->
setFlash
(
'success'
,
'New password was saved.'
);
Yii
::
$app
->
getSession
()
->
setFlash
(
'success'
,
'New password was saved.'
);
$this
->
redirect
(
'index'
);
return
$this
->
goHome
(
);
}
}
return
$this
->
render
(
'resetPassword'
,
array
(
return
$this
->
render
(
'resetPassword'
,
array
(
...
...
apps/basic/controllers/SiteController.php
View file @
27ad7e1f
...
@@ -31,7 +31,7 @@ class SiteController extends Controller
...
@@ -31,7 +31,7 @@ class SiteController extends Controller
{
{
$model
=
new
LoginForm
();
$model
=
new
LoginForm
();
if
(
$model
->
load
(
$_POST
)
&&
$model
->
login
())
{
if
(
$model
->
load
(
$_POST
)
&&
$model
->
login
())
{
return
$this
->
redirect
(
array
(
'site/index'
)
);
return
$this
->
goHome
(
);
}
else
{
}
else
{
return
$this
->
render
(
'login'
,
array
(
return
$this
->
render
(
'login'
,
array
(
'model'
=>
$model
,
'model'
=>
$model
,
...
@@ -42,7 +42,7 @@ class SiteController extends Controller
...
@@ -42,7 +42,7 @@ class SiteController extends Controller
public
function
actionLogout
()
public
function
actionLogout
()
{
{
Yii
::
$app
->
user
->
logout
();
Yii
::
$app
->
user
->
logout
();
return
$this
->
redirect
(
array
(
'site/index'
)
);
return
$this
->
goHome
(
);
}
}
public
function
actionContact
()
public
function
actionContact
()
...
...
apps/basic/views/layouts/main.php
View file @
27ad7e1f
...
@@ -37,7 +37,8 @@ app\config\AppAsset::register($this);
...
@@ -37,7 +37,8 @@ app\config\AppAsset::register($this);
Yii
::
$app
->
user
->
isGuest
?
Yii
::
$app
->
user
->
isGuest
?
array
(
'label'
=>
'Login'
,
'url'
=>
array
(
'/site/login'
))
:
array
(
'label'
=>
'Login'
,
'url'
=>
array
(
'/site/login'
))
:
array
(
'label'
=>
'Logout ('
.
Yii
::
$app
->
user
->
identity
->
username
.
')'
,
'url'
=>
array
(
'/site/logout'
)),
array
(
'label'
=>
'Logout ('
.
Yii
::
$app
->
user
->
identity
->
username
.
')'
,
'url'
=>
array
(
'/site/logout'
)),
)));
),
));
NavBar
::
end
();
NavBar
::
end
();
?>
?>
...
...
framework/yii/web/Controller.php
View file @
27ad7e1f
...
@@ -96,14 +96,21 @@ class Controller extends \yii\base\Controller
...
@@ -96,14 +96,21 @@ class Controller extends \yii\base\Controller
* 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()]].
*
*
* @param array|string $url the URL to be redirected to. [[Html::url()]]
* @param string|array $url the URL to be redirected to. This can be in one of the following formats:
* 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.
* - 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
* @param integer $statusCode the HTTP status code. If null, it will use 302
* for normal requests, and [[ajaxRedirectCode]] for AJAX requests.
* for normal requests, and [[ajaxRedirectCode]] for AJAX requests.
* See [[http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html]]
* See [[http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html]]
* for details about HTTP status code
* for details about HTTP status code
* @return Response the
response object itself
* @return Response the
current response object
*/
*/
public
function
redirect
(
$url
,
$statusCode
=
null
)
public
function
redirect
(
$url
,
$statusCode
=
null
)
{
{
...
@@ -111,6 +118,15 @@ class Controller extends \yii\base\Controller
...
@@ -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.
* Refreshes the current page.
* This method is a shortcut to [[Response::refresh()]].
* This method is a shortcut to [[Response::refresh()]].
* @param string $anchor the anchor that should be appended to the redirection URL.
* @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
...
@@ -563,9 +563,17 @@ class Response extends \yii\base\Response
* return Yii::$app->getResponse()->redirect($url);
* 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.
* @param string|array $url the URL to be redirected to. This can be in one of the following formats:
* The URL can be either relative or absolute. If relative, the host info of the current request
*
* will be prepend to the URL.
* - 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
* @param integer $statusCode the HTTP status code. If null, it will use 302
* for normal requests, and [[ajaxRedirectCode]] for AJAX requests.
* for normal requests, and [[ajaxRedirectCode]] for AJAX requests.
* See [[http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html]]
* See [[http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html]]
...
@@ -574,7 +582,11 @@ class Response extends \yii\base\Response
...
@@ -574,7 +582,11 @@ class Response extends \yii\base\Response
*/
*/
public
function
redirect
(
$url
,
$statusCode
=
null
)
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
)
{
if
(
strpos
(
$url
,
'/'
)
===
0
&&
strpos
(
$url
,
'//'
)
!==
0
)
{
$url
=
Yii
::
$app
->
getRequest
()
->
getHostInfo
()
.
$url
;
$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