Commit 4402073d by Qiang Xue

MVC WIP

parent 311f876b
......@@ -28,8 +28,8 @@ class View extends Component
*/
public $owner;
/**
* @var string|boolean the layout to be applied when [[render()]] or [[renderContent()]] is called.
* If not set, it will use the value of [[Application::layout]]. If false, no layout will be applied.
* @var string the layout to be applied when [[render()]] or [[renderContent()]] is called.
* If not set, it will use the [[Module::layout]] of the currently active module.
*/
public $layout;
/**
......@@ -393,7 +393,8 @@ class View extends Component
* * If the controller's [[Controller::layout|layout]] is a string, use it as the layout name
* and search for the layout file under the layout path of the parent module of the controller;
* * If the controller's [[Controller::layout|layout]] is null, look through its ancestor modules
* and find one whose [[Module::layout|layout]] is not null. Use the layout specified by that module;
* and find the first one whose [[Module::layout|layout]] is not null. Use the layout specified
* by that module;
* - Returns false for all other cases.
*
* Like view names, a layout name can take several formats:
......@@ -425,7 +426,7 @@ class View extends Component
$module = Yii::$application;
}
$view = $this->layout;
} elseif ($this->layout === null && $this->owner instanceof Controller) {
} elseif ($this->owner instanceof Controller) {
if (is_string($this->owner->layout)) {
$module = $this->owner->module;
$view = $this->owner->layout;
......@@ -434,14 +435,13 @@ class View extends Component
while ($module !== null && $module->layout === null) {
$module = $module->module;
}
if ($module === null || !is_string($module->layout)) {
return false;
if ($module !== null && is_string($module->layout)) {
$view = $module->layout;
}
$view = $module->layout;
} else {
return false;
}
} else {
}
if (!isset($view)) {
return false;
}
......
......@@ -9,9 +9,10 @@
namespace yii\console;
use Yii;
use yii\base\Action;
use yii\base\InvalidRequestException;
use yii\base\InvalidRouteException;
use yii\base\Exception;
/**
* Controller is the base class of console command classes.
......@@ -57,35 +58,24 @@ 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
* Validates the parameter being bound to actions.
* This method is invoked when parameters are being bound to the currently requested action.
* Child classes may override this method to throw exceptions when there are missing and/or unknown parameters.
* @param Action $action the currently requested action
* @param array $missingParams the names of the missing parameters
* @param array $unknownParams the unknown parameters (name=>value)
* @throws InvalidRequestException if there are missing or unknown parameters
*/
public function invalidActionParams($action, $exception)
public function validateActionParams($action, $missingParams, $unknownParams)
{
echo \Yii::t('yii', 'Error: {message}', array(
'{message}' => $exception->getMessage(),
));
\Yii::$application->end(1);
}
/**
* This method is invoked when extra parameters are provided to an action while it is executed.
* @param Action $action the action being executed
* @param array $expected the expected action parameters (name => value)
* @param array $actual the actual action parameters (name => value)
*/
public function extraActionParams($action, $expected, $actual)
{
unset($expected['args'], $actual['args']);
$keys = array_diff(array_keys($actual), array_keys($expected));
if (!empty($keys)) {
echo \Yii::t('yii', 'Error: Unknown parameter(s): {params}', array(
'{params}' => implode(', ', $keys),
)) . "\n";
\Yii::$application->end(1);
if (!empty($missingParams)) {
throw new InvalidRequestException(Yii::t('yii', 'Missing required options: {params}', array(
'{params}' => implode(', ', $missingParams),
)));
} elseif (!empty($unknownParams)) {
throw new InvalidRequestException(Yii::t('yii', 'Unknown options: {params}', array(
'{params}' => implode(', ', $unknownParams),
)));
}
}
......
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