Commit 38dcae3d by Qiang Xue

Finished help ccommand.

parent 12932f0d
...@@ -531,11 +531,13 @@ class YiiBase ...@@ -531,11 +531,13 @@ class YiiBase
*/ */
public static function t($category, $message, $params = array(), $source = null, $language = null) public static function t($category, $message, $params = array(), $source = null, $language = null)
{ {
if (self::$app !== null) // todo;
return $params !== array() ? strtr($message, $params) : $message;
if (self::$application !== null)
{ {
if ($source === null) if ($source === null)
$source = $category === 'yii' ? 'coreMessages' : 'messages'; $source = $category === 'yii' ? 'coreMessages' : 'messages';
if (($source = self::$app->getComponent($source)) !== null) if (($source = self::$application->getComponent($source)) !== null)
$message = $source->translate($category, $message, $language); $message = $source->translate($category, $message, $language);
} }
if ($params === array()) if ($params === array())
...@@ -549,7 +551,7 @@ class YiiBase ...@@ -549,7 +551,7 @@ class YiiBase
if (strpos($message, '#') === false) if (strpos($message, '#') === false)
{ {
$chunks = explode('|', $message); $chunks = explode('|', $message);
$expressions = self::$app->getLocale($language)->getPluralRules(); $expressions = self::$application->getLocale($language)->getPluralRules();
if ($n = min(count($chunks), count($expressions))) if ($n = min(count($chunks), count($expressions)))
{ {
for ($i = 0;$i < $n;$i++) for ($i = 0;$i < $n;$i++)
......
...@@ -29,12 +29,23 @@ use yii\base\Exception; ...@@ -29,12 +29,23 @@ use yii\base\Exception;
class Controller extends \yii\base\Controller class Controller extends \yii\base\Controller
{ {
/** /**
* 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
*/
public function invalidActionParams($action, $exception)
{
echo "Error: " . $exception->getMessage() . "\n";
\Yii::$application->end(1);
}
/**
* This method is invoked when extra parameters are provided to an action when it is executed. * This method is invoked when extra parameters are provided to an action when it is executed.
* The default implementation does nothing. * The default implementation does nothing.
* @param Action $action the action being executed * @param Action $action the action being executed
* @param array $expected the expected action parameters (name => value) * @param array $expected the expected action parameters (name => value)
* @param array $actual the actual action parameters (name => value) * @param array $actual the actual action parameters (name => value)
* @throws Exception if any unrecognized parameters are provided
*/ */
public function extraActionParams($action, $expected, $actual) public function extraActionParams($action, $expected, $actual)
{ {
...@@ -42,9 +53,10 @@ class Controller extends \yii\base\Controller ...@@ -42,9 +53,10 @@ class Controller extends \yii\base\Controller
$keys = array_diff(array_keys($actual), array_keys($expected)); $keys = array_diff(array_keys($actual), array_keys($expected));
if (!empty($keys)) { if (!empty($keys)) {
throw new Exception(\Yii::t('yii', 'Unknown parameters: {params}', array( echo "Error: " . \Yii::t('yii', 'Unknown parameters: {params}', array(
'{params}' => implode(', ', $keys), '{params}' => implode(', ', $keys),
))); )) . "\n";
\Yii::$application->end(1);
} }
} }
} }
\ No newline at end of file
...@@ -54,7 +54,7 @@ class ReflectionHelper ...@@ -54,7 +54,7 @@ class ReflectionHelper
} elseif ($param->isDefaultValueAvailable()) { } elseif ($param->isDefaultValueAvailable()) {
$ps[$name] = $param->getDefaultValue(); $ps[$name] = $param->getDefaultValue();
} else { } else {
throw new Exception(\Yii::t('yii', 'Missing required parameter "{name}".', array('{name' => $name))); throw new Exception(\Yii::t('yii', 'Missing required parameter "{name}".', array('{name}' => $name)));
} }
} }
return $ps; return $ps;
......
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