mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
MVC WIP
This commit is contained in:
@ -28,8 +28,8 @@ class View extends Component
|
|||||||
*/
|
*/
|
||||||
public $owner;
|
public $owner;
|
||||||
/**
|
/**
|
||||||
* @var string|boolean the layout to be applied when [[render()]] or [[renderContent()]] is called.
|
* @var string 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.
|
* If not set, it will use the [[Module::layout]] of the currently active module.
|
||||||
*/
|
*/
|
||||||
public $layout;
|
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
|
* * 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;
|
* 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
|
* * 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.
|
* - Returns false for all other cases.
|
||||||
*
|
*
|
||||||
* Like view names, a layout name can take several formats:
|
* Like view names, a layout name can take several formats:
|
||||||
@ -425,7 +426,7 @@ class View extends Component
|
|||||||
$module = Yii::$application;
|
$module = Yii::$application;
|
||||||
}
|
}
|
||||||
$view = $this->layout;
|
$view = $this->layout;
|
||||||
} elseif ($this->layout === null && $this->owner instanceof Controller) {
|
} elseif ($this->owner instanceof Controller) {
|
||||||
if (is_string($this->owner->layout)) {
|
if (is_string($this->owner->layout)) {
|
||||||
$module = $this->owner->module;
|
$module = $this->owner->module;
|
||||||
$view = $this->owner->layout;
|
$view = $this->owner->layout;
|
||||||
@ -434,14 +435,13 @@ class View extends Component
|
|||||||
while ($module !== null && $module->layout === null) {
|
while ($module !== null && $module->layout === null) {
|
||||||
$module = $module->module;
|
$module = $module->module;
|
||||||
}
|
}
|
||||||
if ($module === null || !is_string($module->layout)) {
|
if ($module !== null && is_string($module->layout)) {
|
||||||
return false;
|
$view = $module->layout;
|
||||||
}
|
}
|
||||||
$view = $module->layout;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if (!isset($view)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,9 +9,10 @@
|
|||||||
|
|
||||||
namespace yii\console;
|
namespace yii\console;
|
||||||
|
|
||||||
|
use Yii;
|
||||||
use yii\base\Action;
|
use yii\base\Action;
|
||||||
|
use yii\base\InvalidRequestException;
|
||||||
use yii\base\InvalidRouteException;
|
use yii\base\InvalidRouteException;
|
||||||
use yii\base\Exception;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller is the base class of console command classes.
|
* 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.
|
* Validates the parameter being bound to actions.
|
||||||
* The default implementation will throw an exception.
|
* This method is invoked when parameters are being bound to the currently requested action.
|
||||||
* @param Action $action the action being executed
|
* Child classes may override this method to throw exceptions when there are missing and/or unknown parameters.
|
||||||
* @param Exception $exception the exception about the invalid 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(
|
if (!empty($missingParams)) {
|
||||||
'{message}' => $exception->getMessage(),
|
throw new InvalidRequestException(Yii::t('yii', 'Missing required options: {params}', array(
|
||||||
));
|
'{params}' => implode(', ', $missingParams),
|
||||||
\Yii::$application->end(1);
|
)));
|
||||||
}
|
} elseif (!empty($unknownParams)) {
|
||||||
|
throw new InvalidRequestException(Yii::t('yii', 'Unknown options: {params}', array(
|
||||||
/**
|
'{params}' => implode(', ', $unknownParams),
|
||||||
* 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user