Browse Source

bug fixes.

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
1c375b9097
  1. 2
      framework/YiiBase.php
  2. 3
      framework/base/Module.php
  3. 26
      framework/i18n/I18N.php
  4. 2
      framework/util/FileHelper.php
  5. 2
      framework/views/error.php
  6. 9
      framework/web/Application.php
  7. 54
      framework/web/Controller.php

2
framework/YiiBase.php

@ -521,6 +521,6 @@ class YiiBase
*/ */
public static function t($message, $params = array(), $language = null) public static function t($message, $params = array(), $language = null)
{ {
Yii::$app->getI18N()->translate($message, $params, $language); return Yii::$app->getI18N()->translate($message, $params, $language);
} }
} }

3
framework/base/Module.php

@ -569,7 +569,7 @@ abstract class Module extends Component
Yii::$app->controller = $oldController; Yii::$app->controller = $oldController;
return $status; return $status;
} else { } else {
throw new InvalidRouteException('Unable to resolve the request: ' . trim($this->getUniqueId() . '/' . $route, '/')); throw new InvalidRouteException('Unable to resolve the request "' . trim($this->getUniqueId() . '/' . $route, '/') . '".');
} }
} }
@ -607,6 +607,7 @@ abstract class Module extends Component
$controller = Yii::createObject($this->controllerMap[$id], $id, $this); $controller = Yii::createObject($this->controllerMap[$id], $id, $this);
} elseif (preg_match('/^[a-z0-9\\-_]+$/', $id)) { } elseif (preg_match('/^[a-z0-9\\-_]+$/', $id)) {
$className = StringHelper::id2camel($id) . 'Controller'; $className = StringHelper::id2camel($id) . 'Controller';
$classFile = $this->controllerPath . DIRECTORY_SEPARATOR . $className . '.php'; $classFile = $this->controllerPath . DIRECTORY_SEPARATOR . $className . '.php';
if (is_file($classFile)) { if (is_file($classFile)) {
$className = $this->controllerNamespace . '\\' . $className; $className = $this->controllerNamespace . '\\' . $className;

26
framework/i18n/I18N.php

@ -20,19 +20,19 @@ class I18N extends Component
$category = 'app'; $category = 'app';
} }
$message = $this->getMessageSource($category)->translate($category, $message, $language); // $message = $this->getMessageSource($category)->translate($category, $message, $language);
//
if (!is_array($params)) { // if (!is_array($params)) {
$params = array($params); // $params = array($params);
} // }
//
if (isset($params[0])) { // if (isset($params[0])) {
$message = $this->getPluralFormat($message, $params[0], $language); // $message = $this->getPluralFormat($message, $params[0], $language);
if (!isset($params['{n}'])) { // if (!isset($params['{n}'])) {
$params['{n}'] = $params[0]; // $params['{n}'] = $params[0];
} // }
unset($params[0]); // unset($params[0]);
} // }
return $params === array() ? $message : strtr($message, $params); return $params === array() ? $message : strtr($message, $params);
} }

2
framework/util/FileHelper.php

@ -91,7 +91,7 @@ class FileHelper
public static function localize($file, $language = null, $sourceLanguage = null) public static function localize($file, $language = null, $sourceLanguage = null)
{ {
if ($language === null) { if ($language === null) {
$language = \Yii::$app->getLanguage(); $language = \Yii::$app->language;
} }
if ($sourceLanguage === null) { if ($sourceLanguage === null) {
$sourceLanguage = \Yii::$app->sourceLanguage; $sourceLanguage = \Yii::$app->sourceLanguage;

2
framework/views/error.php

@ -50,7 +50,7 @@ $owner = $this->owner;
</head> </head>
<body> <body>
<h1><?php echo get_class($exception)?></h1> <h1><?php echo $owner->htmlEncode($exception instanceof \yii\base\Exception ? $exception->getName() : get_class($exception)); ?></h1>
<h2><?php echo nl2br($owner->htmlEncode($exception->getMessage()))?> </h2> <h2><?php echo nl2br($owner->htmlEncode($exception->getMessage()))?> </h2>
<p> <p>
The above error occurred while the Web server was processing your request. The above error occurred while the Web server was processing your request.

9
framework/web/Application.php

@ -32,13 +32,8 @@ class Application extends \yii\base\Application
*/ */
public function processRequest() public function processRequest()
{ {
$route = $this->resolveRequest(); $route = isset($_GET['r']) ? $_GET['r'] : '';
return $this->runController($route, null); return $this->runAction($route, $_GET);
}
protected function resolveRequest()
{
return array();
} }
/** /**

54
framework/web/Controller.php

@ -9,10 +9,6 @@
namespace yii\web; namespace yii\web;
use yii\base\Action;
use yii\base\Exception;
use yii\base\HttpException;
/** /**
* Controller is the base class of Web controllers. * Controller is the base class of Web controllers.
* *
@ -22,54 +18,4 @@ use yii\base\HttpException;
*/ */
class Controller extends \yii\base\Controller class Controller extends \yii\base\Controller
{ {
private $_pageTitle;
/**
* Returns the request parameters that will be used for action parameter binding.
* Default implementation simply returns an empty array.
* Child classes may override this method to customize the parameters to be provided
* for action parameter binding (e.g. `$_GET`).
* @return array the request parameters (name-value pairs) to be used for action parameter binding
*/
public function getActionParams()
{
return $_GET;
}
/**
* This method is invoked when the request parameters do not satisfy the requirement of the specified action.
* The default implementation will throw an exception.
* @param Action $action the action being executed
* @param Exception $exception the exception about the invalid parameters
* @throws HttpException $exception a 400 HTTP exception
*/
public function invalidActionParams($action, $exception)
{
throw new HttpException(400, \Yii::t('yii|Your request is invalid.'));
}
/**
* @return string the page title. Defaults to the controller name and the action name.
*/
public function getPageTitle()
{
if($this->_pageTitle !== null) {
return $this->_pageTitle;
}
else {
$name = ucfirst(basename($this->id));
if($this->action!==null && strcasecmp($this->action->id,$this->defaultAction))
return $this->_pageTitle=\Yii::$app->name.' - '.ucfirst($this->action->id).' '.$name;
else
return $this->_pageTitle=\Yii::$app->name.' - '.$name;
}
}
/**
* @param string $value the page title.
*/
public function setPageTitle($value)
{
$this->_pageTitle = $value;
}
} }
Loading…
Cancel
Save