Commit 663d3fed by Alexander Makarov

Added defaultView to ViewAction

parent 96d38820
...@@ -36,6 +36,14 @@ class ViewAction extends Action ...@@ -36,6 +36,14 @@ class ViewAction extends Action
public $viewParam = 'view'; public $viewParam = 'view';
/** /**
* @var string the name of the default view when [[\yii\web\ViewAction::$viewParam]] GET parameter is not provided
* by user. Defaults to 'index'. This should be in the format of 'path/to/view', similar to that given in the
* GET parameter.
* @see \yii\web\ViewAction::$viewPrefix
*/
public $defaultView = 'index';
/**
* @var string a string to be prefixed to the user-specified view name to form a complete view name. * @var string a string to be prefixed to the user-specified view name to form a complete view name.
* For example, if a user requests for `tutorial/chap1`, the corresponding view name will * For example, if a user requests for `tutorial/chap1`, the corresponding view name will
* be `pages/tutorial/chap1`, assuming the prefix is `pages`. * be `pages/tutorial/chap1`, assuming the prefix is `pages`.
...@@ -111,7 +119,7 @@ class ViewAction extends Action ...@@ -111,7 +119,7 @@ class ViewAction extends Action
*/ */
protected function resolveViewName() protected function resolveViewName()
{ {
$viewName = Yii::$app->request->get($this->viewParam); $viewName = Yii::$app->request->get($this->viewParam, $this->defaultView);
if (!is_string($viewName) || !preg_match('/^\w[\w\/\-\.]*$/', $viewName)) { if (!is_string($viewName) || !preg_match('/^\w[\w\/\-\.]*$/', $viewName)) {
if (YII_DEBUG) { if (YII_DEBUG) {
......
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