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
6aa86712
Commit
6aa86712
authored
Mar 28, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
User WIP
parent
b7be92ce
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
32 deletions
+83
-32
Application.php
framework/web/Application.php
+28
-2
Controller.php
framework/web/Controller.php
+16
-0
Identity.php
framework/web/Identity.php
+3
-1
Response.php
framework/web/Response.php
+36
-29
User.php
framework/web/User.php
+0
-0
No files found.
framework/web/Application.php
View file @
6aa86712
...
...
@@ -7,7 +7,7 @@
namespace
yii\web
;
use
yii\base\InvalidParamException
;
use
Yii
;
/**
* Application is the base class for all application classes.
...
...
@@ -28,7 +28,7 @@ class Application extends \yii\base\Application
public
function
registerDefaultAliases
()
{
parent
::
registerDefaultAliases
();
\
Yii
::
$aliases
[
'@webroot'
]
=
dirname
(
$_SERVER
[
'SCRIPT_FILENAME'
]);
Yii
::
$aliases
[
'@webroot'
]
=
dirname
(
$_SERVER
[
'SCRIPT_FILENAME'
]);
}
/**
...
...
@@ -41,6 +41,32 @@ class Application extends \yii\base\Application
return
$this
->
runAction
(
$route
,
$params
);
}
private
$_homeUrl
;
/**
* @return string the homepage URL
*/
public
function
getHomeUrl
()
{
if
(
$this
->
_homeUrl
===
null
)
{
if
(
$this
->
getUrlManager
()
->
showScriptName
)
{
return
$this
->
getRequest
()
->
getScriptUrl
();
}
else
{
return
$this
->
getRequest
()
->
getBaseUrl
()
.
'/'
;
}
}
else
{
return
$this
->
_homeUrl
;
}
}
/**
* @param string $value the homepage URL
*/
public
function
setHomeUrl
(
$value
)
{
$this
->
_homeUrl
=
$value
;
}
/**
* Returns the request component.
* @return Request the request component
...
...
framework/web/Controller.php
View file @
6aa86712
...
...
@@ -8,6 +8,7 @@
namespace
yii\web
;
use
Yii
;
use
yii\helpers\Html
;
/**
* Controller is the base class of Web controllers.
...
...
@@ -41,4 +42,18 @@ class Controller extends \yii\base\Controller
return
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$route
,
$params
);
}
/**
* Redirects the browser to the specified URL or route (controller/action).
* @param mixed $url the URL to be redirected to. If the parameter is an array,
* the first element must be a route to a controller action and the rest
* are GET parameters in name-value pairs.
* @param boolean $terminate whether to terminate the current application after calling this method. Defaults to true.
* @param integer $statusCode the HTTP status code. Defaults to 302. See {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html}
* for details about HTTP status code.
*/
public
function
redirect
(
$url
,
$terminate
=
true
,
$statusCode
=
302
)
{
$url
=
Html
::
url
(
$url
);
Yii
::
$app
->
getResponse
()
->
redirect
(
$url
,
$terminate
,
$statusCode
);
}
}
\ No newline at end of file
framework/web/Identity.php
View file @
6aa86712
...
...
@@ -38,7 +38,8 @@ interface Identity
* Finds an identity by the given ID.
* @param string|integer $id the ID to be looked for
* @return Identity the identity object that matches the given ID.
* Null should be returned if such an identity cannot be found.
* Null should be returned if such an identity cannot be found
* or the identity is not in an active state (disabled, deleted, etc.)
*/
public
static
function
findIdentity
(
$id
);
}
\ No newline at end of file
framework/web/Response.php
View file @
6aa86712
...
...
@@ -107,37 +107,42 @@ class Response extends \yii\base\Response
* <li>addHeaders: an array of additional http headers in header-value pairs (available since version 1.1.10)</li>
* </ul>
*/
public
function
xSendFile
(
$filePath
,
$options
=
array
())
public
function
xSendFile
(
$filePath
,
$options
=
array
())
{
if
(
!
isset
(
$options
[
'forceDownload'
])
||
$options
[
'forceDownload'
])
$disposition
=
'attachment'
;
else
$disposition
=
'inline'
;
if
(
!
isset
(
$options
[
'forceDownload'
])
||
$options
[
'forceDownload'
])
{
$disposition
=
'attachment'
;
}
else
{
$disposition
=
'inline'
;
}
if
(
!
isset
(
$options
[
'saveName'
]))
$options
[
'saveName'
]
=
basename
(
$filePath
);
if
(
!
isset
(
$options
[
'saveName'
]))
{
$options
[
'saveName'
]
=
basename
(
$filePath
);
}
if
(
!
isset
(
$options
[
'mimeType'
]))
{
if
((
$options
[
'mimeType'
]
=
CFileHelper
::
getMimeTypeByExtension
(
$filePath
))
===
null
)
$options
[
'mimeType'
]
=
'text/plain'
;
if
(
!
isset
(
$options
[
'mimeType'
]))
{
if
((
$options
[
'mimeType'
]
=
CFileHelper
::
getMimeTypeByExtension
(
$filePath
))
===
null
)
{
$options
[
'mimeType'
]
=
'text/plain'
;
}
}
if
(
!
isset
(
$options
[
'xHeader'
]))
$options
[
'xHeader'
]
=
'X-Sendfile'
;
if
(
!
isset
(
$options
[
'xHeader'
]))
{
$options
[
'xHeader'
]
=
'X-Sendfile'
;
}
if
(
$options
[
'mimeType'
]
!==
null
)
header
(
'Content-type: '
.
$options
[
'mimeType'
]);
header
(
'Content-Disposition: '
.
$disposition
.
'; filename="'
.
$options
[
'saveName'
]
.
'"'
);
if
(
isset
(
$options
[
'addHeaders'
]))
{
foreach
(
$options
[
'addHeaders'
]
as
$header
=>
$value
)
header
(
$header
.
': '
.
$value
);
if
(
$options
[
'mimeType'
]
!==
null
)
{
header
(
'Content-type: '
.
$options
[
'mimeType'
]);
}
header
(
'Content-Disposition: '
.
$disposition
.
'; filename="'
.
$options
[
'saveName'
]
.
'"'
);
if
(
isset
(
$options
[
'addHeaders'
]))
{
foreach
(
$options
[
'addHeaders'
]
as
$header
=>
$value
)
{
header
(
$header
.
': '
.
$value
);
}
}
header
(
trim
(
$options
[
'xHeader'
])
.
': '
.
$filePath
);
header
(
trim
(
$options
[
'xHeader'
])
.
': '
.
$filePath
);
if
(
!
isset
(
$options
[
'terminate'
])
||
$options
[
'terminate'
])
Yii
::
app
()
->
end
();
if
(
!
isset
(
$options
[
'terminate'
])
||
$options
[
'terminate'
])
{
Yii
::
$app
->
end
();
}
}
/**
...
...
@@ -148,13 +153,15 @@ class Response extends \yii\base\Response
* @param integer $statusCode the HTTP status code. Defaults to 302. See {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html}
* for details about HTTP status code.
*/
public
function
redirect
(
$url
,
$terminate
=
true
,
$statusCode
=
302
)
public
function
redirect
(
$url
,
$terminate
=
true
,
$statusCode
=
302
)
{
if
(
strpos
(
$url
,
'/'
)
===
0
&&
strpos
(
$url
,
'//'
)
!==
0
)
$url
=
$this
->
getHostInfo
()
.
$url
;
header
(
'Location: '
.
$url
,
true
,
$statusCode
);
if
(
$terminate
)
Yii
::
app
()
->
end
();
if
(
strpos
(
$url
,
'/'
)
===
0
&&
strpos
(
$url
,
'//'
)
!==
0
)
{
$url
=
Yii
::
$app
->
getRequest
()
->
getHostInfo
()
.
$url
;
}
header
(
'Location: '
.
$url
,
true
,
$statusCode
);
if
(
$terminate
)
{
Yii
::
$app
->
end
();
}
}
...
...
framework/web/User.php
View file @
6aa86712
This diff is collapsed.
Click to expand it.
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