Commit 6aa86712 by Qiang Xue

User WIP

parent b7be92ce
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace yii\web; namespace yii\web;
use yii\base\InvalidParamException; use Yii;
/** /**
* Application is the base class for all application classes. * Application is the base class for all application classes.
...@@ -28,7 +28,7 @@ class Application extends \yii\base\Application ...@@ -28,7 +28,7 @@ class Application extends \yii\base\Application
public function registerDefaultAliases() public function registerDefaultAliases()
{ {
parent::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 ...@@ -41,6 +41,32 @@ class Application extends \yii\base\Application
return $this->runAction($route, $params); 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. * Returns the request component.
* @return Request the request component * @return Request the request component
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace yii\web; namespace yii\web;
use Yii; use Yii;
use yii\helpers\Html;
/** /**
* Controller is the base class of Web controllers. * Controller is the base class of Web controllers.
...@@ -41,4 +42,18 @@ class Controller extends \yii\base\Controller ...@@ -41,4 +42,18 @@ class Controller extends \yii\base\Controller
return Yii::$app->getUrlManager()->createUrl($route, $params); 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
...@@ -38,7 +38,8 @@ interface Identity ...@@ -38,7 +38,8 @@ interface Identity
* Finds an identity by the given ID. * Finds an identity by the given ID.
* @param string|integer $id the ID to be looked for * @param string|integer $id the ID to be looked for
* @return Identity the identity object that matches the given ID. * @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); public static function findIdentity($id);
} }
\ No newline at end of file
...@@ -107,37 +107,42 @@ class Response extends \yii\base\Response ...@@ -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> * <li>addHeaders: an array of additional http headers in header-value pairs (available since version 1.1.10)</li>
* </ul> * </ul>
*/ */
public function xSendFile($filePath, $options=array()) public function xSendFile($filePath, $options = array())
{ {
if(!isset($options['forceDownload']) || $options['forceDownload']) if (!isset($options['forceDownload']) || $options['forceDownload']) {
$disposition='attachment'; $disposition = 'attachment';
else } else {
$disposition='inline'; $disposition = 'inline';
}
if(!isset($options['saveName'])) if (!isset($options['saveName'])) {
$options['saveName']=basename($filePath); $options['saveName'] = basename($filePath);
}
if(!isset($options['mimeType'])) if (!isset($options['mimeType'])) {
{ if (($options['mimeType'] = CFileHelper::getMimeTypeByExtension($filePath)) === null) {
if(($options['mimeType']=CFileHelper::getMimeTypeByExtension($filePath))===null) $options['mimeType'] = 'text/plain';
$options['mimeType']='text/plain'; }
} }
if(!isset($options['xHeader'])) if (!isset($options['xHeader'])) {
$options['xHeader']='X-Sendfile'; $options['xHeader'] = 'X-Sendfile';
}
if($options['mimeType'] !== null) if ($options['mimeType'] !== null) {
header('Content-type: '.$options['mimeType']); 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('Content-Disposition: ' . $disposition . '; filename="' . $options['saveName'] . '"');
if (isset($options['addHeaders'])) {
foreach ($options['addHeaders'] as $header => $value) {
header($header . ': ' . $value);
}
}
header(trim($options['xHeader']) . ': ' . $filePath);
if(!isset($options['terminate']) || $options['terminate']) if (!isset($options['terminate']) || $options['terminate']) {
Yii::app()->end(); Yii::$app->end();
}
} }
/** /**
...@@ -148,13 +153,15 @@ class Response extends \yii\base\Response ...@@ -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} * @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. * 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) if (strpos($url, '/') === 0 && strpos($url, '//') !== 0) {
$url=$this->getHostInfo().$url; $url = Yii::$app->getRequest()->getHostInfo() . $url;
header('Location: '.$url, true, $statusCode); }
if($terminate) header('Location: ' . $url, true, $statusCode);
Yii::app()->end(); if ($terminate) {
Yii::$app->end();
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment