From f576add9e97b97662a56911330dfd9a75fca9fb5 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sun, 11 Aug 2013 20:03:01 -0400 Subject: [PATCH 001/131] Fixes #744: simplified Yii autoloader. --- framework/yii/YiiBase.php | 33 +++------------------------- framework/yii/base/UnknownClassException.php | 25 --------------------- framework/yii/classes.php | 1 - 3 files changed, 3 insertions(+), 56 deletions(-) delete mode 100644 framework/yii/base/UnknownClassException.php diff --git a/framework/yii/YiiBase.php b/framework/yii/YiiBase.php index cb2380a..2f2bf61 100644 --- a/framework/yii/YiiBase.php +++ b/framework/yii/YiiBase.php @@ -9,7 +9,6 @@ namespace yii; use yii\base\Exception; use yii\base\InvalidConfigException; use yii\base\InvalidParamException; -use yii\base\UnknownClassException; use yii\log\Logger; /** @@ -69,11 +68,6 @@ class YiiBase */ public static $classMap = array(); /** - * @var boolean whether to search PHP include_path when autoloading unknown classes. - * You may want to turn this off if you are also using autoloaders from other libraries. - */ - public static $enableIncludePath = false; - /** * @var \yii\console\Application|\yii\web\Application the application instance */ public static $app; @@ -338,12 +332,8 @@ class YiiBase * 3. If the class is named in PEAR style (e.g. `PHPUnit_Framework_TestCase`), * it will attempt to include the file associated with the corresponding path alias * (e.g. `@PHPUnit/Framework/TestCase.php`); - * 4. Search PHP include_path for the actual class file if [[enableIncludePath]] is true; - * 5. Return false so that other autoloaders have chance to include the class file. * - * @param string $className the fully qualified class name without leading \ - * @return boolean whether the class has been loaded successfully - * @throws UnknownClassException if the class does not exist in the class file + * @param string $className the fully qualified class name without a leading backslash "\" */ public static function autoload($className) { @@ -352,6 +342,7 @@ class YiiBase if ($classFile[0] === '@') { $classFile = static::getAlias($classFile); } + include($classFile); } else { // follow PSR-0 to determine the class file if (($pos = strrpos($className, '\\')) !== false) { @@ -367,27 +358,9 @@ class YiiBase $fullPath = static::getAlias('@' . $path, false); if ($fullPath !== false && is_file($fullPath)) { $classFile = $fullPath; + include($classFile); } } - - // search include_path - if (!isset($classFile) && self::$enableIncludePath && ($fullPath = stream_resolve_include_path($path)) !== false) { - $classFile = $fullPath; - } - - if (!isset($classFile)) { - // return false to let other autoloaders to try loading the class - return false; - } - } - - include($classFile); - - if (class_exists($className, false) || interface_exists($className, false) || - function_exists('trait_exists') && trait_exists($className, false)) { - return true; - } else { - throw new UnknownClassException("Unable to find '$className' in file: $classFile"); } } diff --git a/framework/yii/base/UnknownClassException.php b/framework/yii/base/UnknownClassException.php deleted file mode 100644 index 7b893d4..0000000 --- a/framework/yii/base/UnknownClassException.php +++ /dev/null @@ -1,25 +0,0 @@ - - * @since 2.0 - */ -class UnknownClassException extends Exception -{ - /** - * @return string the user-friendly name of this exception - */ - public function getName() - { - return \Yii::t('yii', 'Unknown Class'); - } -} diff --git a/framework/yii/classes.php b/framework/yii/classes.php index 367cc9a..3c56749 100644 --- a/framework/yii/classes.php +++ b/framework/yii/classes.php @@ -37,7 +37,6 @@ return array( 'yii\base\Request' => YII_PATH . '/base/Request.php', 'yii\base\Response' => YII_PATH . '/base/Response.php', 'yii\base\Theme' => YII_PATH . '/base/Theme.php', - 'yii\base\UnknownClassException' => YII_PATH . '/base/UnknownClassException.php', 'yii\base\UnknownMethodException' => YII_PATH . '/base/UnknownMethodException.php', 'yii\base\UnknownPropertyException' => YII_PATH . '/base/UnknownPropertyException.php', 'yii\base\UserException' => YII_PATH . '/base/UserException.php', From b96fd24ef59cc217db36aa97f93b278f47a8988c Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Mon, 12 Aug 2013 02:26:30 +0200 Subject: [PATCH 002/131] Finished documentation of Console Helper and Controller fixes #33 --- framework/yii/console/Controller.php | 9 +++-- .../yii/console/controllers/MigrateController.php | 2 +- framework/yii/helpers/ConsoleBase.php | 43 ++++++++++++++-------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/framework/yii/console/Controller.php b/framework/yii/console/Controller.php index 667031f..fd6d0de 100644 --- a/framework/yii/console/Controller.php +++ b/framework/yii/console/Controller.php @@ -43,8 +43,8 @@ class Controller extends \yii\base\Controller /** * Returns a value indicating whether ANSI color is enabled. * - * ANSI color is enabled only if [[color]] is not set or is set true, - * and the terminal must support ANSI color. + * ANSI color is enabled only if [[color]] is set true or is not set + * and the terminal supports ANSI color. * * @param resource $stream the stream to check. * @return boolean Whether to enable ANSI style in output. @@ -140,7 +140,7 @@ class Controller extends \yii\base\Controller * Example: * * ~~~ - * $this->ansiFormat('This will be red and underlined.', Console::FG_RED, Console::UNDERLINE); + * echo $this->ansiFormat('This will be red and underlined.', Console::FG_RED, Console::UNDERLINE); * ~~~ * * @param string $string the string to be formatted @@ -234,7 +234,8 @@ class Controller extends \yii\base\Controller * * @param string $message to echo out before waiting for user input * @param boolean $default this value is returned if no selection is made. - * @return boolean whether user confirmed + * @return boolean whether user confirmed. + * Will return true if [[interactive]] is false. */ public function confirm($message, $default = false) { diff --git a/framework/yii/console/controllers/MigrateController.php b/framework/yii/console/controllers/MigrateController.php index 287b887..e2c771c 100644 --- a/framework/yii/console/controllers/MigrateController.php +++ b/framework/yii/console/controllers/MigrateController.php @@ -97,7 +97,7 @@ class MigrateController extends Controller public function globalOptions() { return array_merge(parent::globalOptions(), array( - 'migrationPath', 'migrationTable', 'db', 'templateFile', 'interactive' + 'migrationPath', 'migrationTable', 'db', 'templateFile', 'interactive', 'color' )); } diff --git a/framework/yii/helpers/ConsoleBase.php b/framework/yii/helpers/ConsoleBase.php index 2372a64..3593e74 100644 --- a/framework/yii/helpers/ConsoleBase.php +++ b/framework/yii/helpers/ConsoleBase.php @@ -233,9 +233,10 @@ class ConsoleBase /** * Returns the ANSI format code. * - * @param array $format You can pass any of the FG_*, BG_* and TEXT_* constants and also [[xtermFgColor]] and [[xtermBgColor]]. - * TODO: documentation - * @return string + * @param array $format An array containing formatting values. + * You can pass any of the FG_*, BG_* and TEXT_* constants + * and also [[xtermFgColor]] and [[xtermBgColor]] to specify a format. + * @return string The ANSI format code according to the given formatting constants. */ public static function ansiFormatCode($format) { @@ -243,10 +244,12 @@ class ConsoleBase } /** - * Sets the ANSI format for any text that is printed afterwards. + * Echoes an ANSI format code that affects the formatting of any text that is printed afterwards. * - * @param array $format You can pass any of the FG_*, BG_* and TEXT_* constants and also [[xtermFgColor]] and [[xtermBgColor]]. - * TODO: documentation + * @param array $format An array containing formatting values. + * You can pass any of the FG_*, BG_* and TEXT_* constants + * and also [[xtermFgColor]] and [[xtermBgColor]] to specify a format. + * @see ansiFormatCode() * @see ansiFormatEnd() */ public static function beginAnsiFormat($format) @@ -256,8 +259,8 @@ class ConsoleBase /** * Resets any ANSI format set by previous method [[ansiFormatBegin()]] - * Any output after this is will have default text style. - * This is equal to + * Any output after this will have default text format. + * This is equal to calling * * ```php * echo Console::ansiFormatCode(array(Console::RESET)) @@ -272,8 +275,9 @@ class ConsoleBase * Will return a string formatted with the given ANSI style * * @param string $string the string to be formatted - * @param array $format array containing formatting values. - * You can pass any of the FG_*, BG_* and TEXT_* constants and also [[xtermFgColor]] and [[xtermBgColor]]. + * @param array $format An array containing formatting values. + * You can pass any of the FG_*, BG_* and TEXT_* constants + * and also [[xtermFgColor]] and [[xtermBgColor]] to specify a format. * @return string */ public static function ansiFormat($string, $format = array()) @@ -284,7 +288,7 @@ class ConsoleBase /** * Returns the ansi format code for xterm foreground color. - * You can pass the returnvalue of this to one of the formatting methods: + * You can pass the return value of this to one of the formatting methods: * [[ansiFormat]], [[ansiFormatCode]], [[beginAnsiFormat]] * * @param integer $colorCode xterm color code @@ -297,8 +301,8 @@ class ConsoleBase } /** - * Returns the ansi format code for xterm foreground color. - * You can pass the returnvalue of this to one of the formatting methods: + * Returns the ansi format code for xterm background color. + * You can pass the return value of this to one of the formatting methods: * [[ansiFormat]], [[ansiFormatCode]], [[beginAnsiFormat]] * * @param integer $colorCode xterm color code @@ -321,7 +325,12 @@ class ConsoleBase return preg_replace('/\033\[[\d;?]*\w/', '', $string); } - // TODO refactor and review + /** + * Converts an ANSI formatted string to HTML + * @param $string + * @return mixed + */ + // TODO rework/refactor according to https://github.com/yiisoft/yii2/issues/746 public static function ansiToHtml($string) { $tags = 0; @@ -427,6 +436,7 @@ class ConsoleBase ); } + // TODO rework/refactor according to https://github.com/yiisoft/yii2/issues/746 public function markdownToAnsi() { // TODO implement @@ -435,7 +445,6 @@ class ConsoleBase /** * Converts a string to ansi formatted by replacing patterns like %y (for yellow) with ansi control codes * - * // TODO documentation * Uses almost the same syntax as https://github.com/pear/Console_Color2/blob/master/Console/Color2.php * The conversion table is: ('bold' meaning 'light' on some * terminals). It's almost the same conversion table irssi uses. @@ -468,6 +477,7 @@ class ConsoleBase * @param bool $colored Should the string be colored? * @return string */ + // TODO rework/refactor according to https://github.com/yiisoft/yii2/issues/746 public static function renderColoredString($string, $colored = true) { static $conversions = array( @@ -531,6 +541,7 @@ class ConsoleBase * @access public * @return string */ + // TODO rework/refactor according to https://github.com/yiisoft/yii2/issues/746 public static function escape($string) { return str_replace('%', '%%', $string); @@ -562,7 +573,7 @@ class ConsoleBase } /** - * Usage: list($w, $h) = ConsoleHelper::getScreenSize(); + * Usage: list($width, $height) = ConsoleHelper::getScreenSize(); * * @param bool $refresh whether to force checking and not re-use cached size value. * This is useful to detect changing window size while the application is running but may From 293b1737e11740783e228f39017eb2c12ae06f46 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Mon, 12 Aug 2013 02:36:47 +0200 Subject: [PATCH 003/131] cleanup YiiBase::autoload() --- framework/yii/YiiBase.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/framework/yii/YiiBase.php b/framework/yii/YiiBase.php index 2f2bf61..2834d7e 100644 --- a/framework/yii/YiiBase.php +++ b/framework/yii/YiiBase.php @@ -353,11 +353,10 @@ class YiiBase $path = str_replace('_', '/', $className) . '.php'; } - // try via path alias first + // try loading via path alias if (strpos($path, '/') !== false) { - $fullPath = static::getAlias('@' . $path, false); - if ($fullPath !== false && is_file($fullPath)) { - $classFile = $fullPath; + $classFile = static::getAlias('@' . $path, false); + if ($classFile !== false && is_file($classFile)) { include($classFile); } } From 534aa4f93c89e3bb20a0554b7dbb7b2bb0c42b61 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 12 Aug 2013 07:17:43 -0400 Subject: [PATCH 004/131] Support auto-activation of Nav. --- apps/basic/views/layouts/main.php | 8 ++--- framework/yii/bootstrap/Nav.php | 67 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/apps/basic/views/layouts/main.php b/apps/basic/views/layouts/main.php index 709ad78..67b74af 100644 --- a/apps/basic/views/layouts/main.php +++ b/apps/basic/views/layouts/main.php @@ -1,7 +1,7 @@ 'navbar-inverse navbar-fixed-top', ), )); - echo Menu::widget(array( - 'options' => array('class' => 'nav navbar-nav pull-right'), + echo Nav::widget(array( + 'options' => array('class' => 'navbar-nav pull-right'), 'items' => array( array('label' => 'Home', 'url' => array('/site/index')), array('label' => 'About', 'url' => array('/site/about')), diff --git a/framework/yii/bootstrap/Nav.php b/framework/yii/bootstrap/Nav.php index 5b5d40b..38451d1 100644 --- a/framework/yii/bootstrap/Nav.php +++ b/framework/yii/bootstrap/Nav.php @@ -7,6 +7,7 @@ namespace yii\bootstrap; +use Yii; use yii\base\InvalidConfigException; use yii\helpers\ArrayHelper; use yii\helpers\Html; @@ -21,9 +22,8 @@ use yii\helpers\Html; * 'items' => array( * array( * 'label' => 'Home', - * 'url' => '/', + * 'url' => array('site/index'), * 'linkOptions' => array(...), - * 'active' => true, * ), * array( * 'label' => 'Dropdown', @@ -63,7 +63,7 @@ class Nav extends Widget * - linkOptions: array, optional, the HTML attributes of the item's link. * - options: array, optional, the HTML attributes of the item container (LI). * - active: boolean, optional, whether the item should be on active state or not. - * - dropdown: array|string, optional, the configuration array for creating a [[Dropdown]] widget, + * - items: array|string, optional, the configuration array for creating a [[Dropdown]] widget, * or a string representing the dropdown menu. Note that Bootstrap does not support sub-dropdown menus. */ public $items = array(); @@ -71,6 +71,26 @@ class Nav extends Widget * @var boolean whether the nav items labels should be HTML-encoded. */ public $encodeLabels = true; + /** + * @var boolean whether to automatically activate items according to whether their route setting + * matches the currently requested route. + * @see isItemActive + */ + public $activateItems = true; + /** + * @var string the route used to determine if a menu item is active or not. + * If not set, it will use the route of the current request. + * @see params + * @see isItemActive + */ + public $route; + /** + * @var array the parameters used to determine if a menu item is active or not. + * If not set, it will use `$_GET`. + * @see route + * @see isItemActive + */ + public $params; /** @@ -79,6 +99,12 @@ class Nav extends Widget public function init() { parent::init(); + if ($this->route === null && Yii::$app->controller !== null) { + $this->route = Yii::$app->controller->getRoute(); + } + if ($this->params === null) { + $this->params = $_GET; + } Html::addCssClass($this->options, 'nav'); } @@ -124,7 +150,13 @@ class Nav extends Widget $url = Html::url(ArrayHelper::getValue($item, 'url', '#')); $linkOptions = ArrayHelper::getValue($item, 'linkOptions', array()); - if (ArrayHelper::getValue($item, 'active')) { + if (isset($item['active'])) { + $active = ArrayHelper::remove($item, 'active', false); + } else { + $active = $this->isItemActive($item); + } + + if ($active) { Html::addCssClass($options, 'active'); } @@ -144,4 +176,31 @@ class Nav extends Widget return Html::tag('li', Html::a($label, $url, $linkOptions) . $items, $options); } + + + /** + * Checks whether a menu item is active. + * This is done by checking if [[route]] and [[params]] match that specified in the `url` option of the menu item. + * When the `url` option of a menu item is specified in terms of an array, its first element is treated + * as the route for the item and the rest of the elements are the associated parameters. + * Only when its route and parameters match [[route]] and [[params]], respectively, will a menu item + * be considered active. + * @param array $item the menu item to be checked + * @return boolean whether the menu item is active + */ + protected function isItemActive($item) + { + if (isset($item['url']) && is_array($item['url']) && trim($item['url'][0], '/') === $this->route) { + unset($item['url']['#']); + if (count($item['url']) > 1) { + foreach (array_splice($item['url'], 1) as $name => $value) { + if (!isset($this->params[$name]) || $this->params[$name] != $value) { + return false; + } + } + } + return true; + } + return false; + } } From 2885d0988f48e1eb7a732cee209164ab3cf9a58f Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 12 Aug 2013 07:18:21 -0400 Subject: [PATCH 005/131] doc fix. --- framework/yii/bootstrap/NavBar.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/yii/bootstrap/NavBar.php b/framework/yii/bootstrap/NavBar.php index 27eb6cd..d9dd2cd 100644 --- a/framework/yii/bootstrap/NavBar.php +++ b/framework/yii/bootstrap/NavBar.php @@ -21,7 +21,7 @@ use yii\helpers\Html; * use yii\widgets\Menu; * * NavBar::begin(array('brandLabel' => 'NavBar Test')); - * echo Menu::widget(array( + * echo Nav::widget(array( * 'items' => array( * array('label' => 'Home', 'url' => array('/site/index')), * array('label' => 'About', 'url' => array('/site/about')), From 3f8e9b7a846daba4c551174e677668265d0bbeff Mon Sep 17 00:00:00 2001 From: Luciano Baraglia Date: Mon, 12 Aug 2013 12:21:28 -0300 Subject: [PATCH 006/131] Login url fix when called from a module --- framework/yii/web/User.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/yii/web/User.php b/framework/yii/web/User.php index e202e8e..c93bdcc 100644 --- a/framework/yii/web/User.php +++ b/framework/yii/web/User.php @@ -45,12 +45,12 @@ class User extends Component * the name-value pairs are GET parameters used to construct the login URL. For example, * * ~~~ - * array('site/login', 'ref' => 1) + * array('/site/login', 'ref' => 1) * ~~~ * * If this property is null, a 403 HTTP exception will be raised when [[loginRequired()]] is called. */ - public $loginUrl = array('site/login'); + public $loginUrl = array('/site/login'); /** * @var array the configuration of the identity cookie. This property is used only when [[enableAutoLogin]] is true. * @see Cookie From 21eab824138f5d1248178796bfa940f17e5259e2 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 12 Aug 2013 12:01:59 -0400 Subject: [PATCH 007/131] Refactored redirect() methods. --- framework/yii/web/Controller.php | 5 +++-- framework/yii/web/Response.php | 8 ++++---- framework/yii/web/User.php | 3 +-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/framework/yii/web/Controller.php b/framework/yii/web/Controller.php index 821a0fd..137b630 100644 --- a/framework/yii/web/Controller.php +++ b/framework/yii/web/Controller.php @@ -9,6 +9,7 @@ namespace yii\web; use Yii; use yii\base\InlineAction; +use yii\helpers\Html; /** * Controller is the base class of Web controllers. @@ -95,7 +96,7 @@ class Controller extends \yii\base\Controller * Redirects the browser to the specified URL. * This method is a shortcut to [[Response::redirect()]]. * - * @param array|string $url the URL to be redirected to. [[\yii\helpers\Html::url()]] + * @param array|string $url the URL to be redirected to. [[Html::url()]] * will be used to normalize the URL. If the resulting URL is still a relative URL * (one without host info), the current request host info will be used. * @param integer $statusCode the HTTP status code. If null, it will use 302 @@ -106,7 +107,7 @@ class Controller extends \yii\base\Controller */ public function redirect($url, $statusCode = null) { - return Yii::$app->getResponse()->redirect($url, $statusCode); + return Yii::$app->getResponse()->redirect(Html::url($url), $statusCode); } /** diff --git a/framework/yii/web/Response.php b/framework/yii/web/Response.php index c7855f6..a9190b5 100644 --- a/framework/yii/web/Response.php +++ b/framework/yii/web/Response.php @@ -563,9 +563,9 @@ class Response extends \yii\base\Response * return Yii::$app->getResponse()->redirect($url); * ~~~ * - * @param array|string $url the URL to be redirected to. [[\yii\helpers\Html::url()]] - * will be used to normalize the URL. If the resulting URL is still a relative URL - * (one without host info), the current request host info will be used. + * @param string $url the URL to be redirected to. This can be a URL or an alias of the URL. + * The URL can be either relative or absolute. If relative, the host info of the current request + * will be prepend to the URL. * @param integer $statusCode the HTTP status code. If null, it will use 302 * for normal requests, and [[ajaxRedirectCode]] for AJAX requests. * See [[http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html]] @@ -574,7 +574,7 @@ class Response extends \yii\base\Response */ public function redirect($url, $statusCode = null) { - $url = Html::url($url); + $url = Yii::getAlias($url); if (strpos($url, '/') === 0 && strpos($url, '//') !== 0) { $url = Yii::$app->getRequest()->getHostInfo() . $url; } diff --git a/framework/yii/web/User.php b/framework/yii/web/User.php index e202e8e..0ad8f68 100644 --- a/framework/yii/web/User.php +++ b/framework/yii/web/User.php @@ -283,8 +283,7 @@ class User extends Component $this->setReturnUrl($request->getUrl()); } if ($this->loginUrl !== null) { - $response = Yii::$app->getResponse(); - $response->redirect($this->loginUrl)->send(); + Yii::$app->getResponse()->redirect($this->loginUrl)->send(); exit(); } else { throw new HttpException(403, Yii::t('yii', 'Login Required')); From 89fa7ed3cbb77d61e28a2ba88d67cdd499d1f95c Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 12 Aug 2013 12:02:59 -0400 Subject: [PATCH 008/131] Reverted the change to User::loginUrl. --- framework/yii/web/User.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/yii/web/User.php b/framework/yii/web/User.php index b55a38c..0ad8f68 100644 --- a/framework/yii/web/User.php +++ b/framework/yii/web/User.php @@ -45,12 +45,12 @@ class User extends Component * the name-value pairs are GET parameters used to construct the login URL. For example, * * ~~~ - * array('/site/login', 'ref' => 1) + * array('site/login', 'ref' => 1) * ~~~ * * If this property is null, a 403 HTTP exception will be raised when [[loginRequired()]] is called. */ - public $loginUrl = array('/site/login'); + public $loginUrl = array('site/login'); /** * @var array the configuration of the identity cookie. This property is used only when [[enableAutoLogin]] is true. * @see Cookie From 27ad7e1fc7db0d958d97add09fac2fbf11077298 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 12 Aug 2013 13:19:37 -0400 Subject: [PATCH 009/131] Added Controller::goHome(). --- .../backend/controllers/SiteController.php | 4 ++-- .../frontend/controllers/SiteController.php | 10 ++++----- apps/basic/controllers/SiteController.php | 4 ++-- apps/basic/views/layouts/main.php | 3 ++- framework/yii/web/Controller.php | 24 ++++++++++++++++++---- framework/yii/web/Response.php | 20 ++++++++++++++---- 6 files changed, 47 insertions(+), 18 deletions(-) diff --git a/apps/advanced/backend/controllers/SiteController.php b/apps/advanced/backend/controllers/SiteController.php index 09052d2..480406a 100644 --- a/apps/advanced/backend/controllers/SiteController.php +++ b/apps/advanced/backend/controllers/SiteController.php @@ -17,7 +17,7 @@ class SiteController extends Controller { $model = new LoginForm(); if ($model->load($_POST) && $model->login()) { - return $this->redirect(array('site/index')); + return $this->goHome(); } else { return $this->render('login', array( 'model' => $model, @@ -28,6 +28,6 @@ class SiteController extends Controller public function actionLogout() { Yii::$app->user->logout(); - return $this->redirect(array('site/index')); + return $this->goHome(); } } diff --git a/apps/advanced/frontend/controllers/SiteController.php b/apps/advanced/frontend/controllers/SiteController.php index c4f7f53..0c1b2f5 100644 --- a/apps/advanced/frontend/controllers/SiteController.php +++ b/apps/advanced/frontend/controllers/SiteController.php @@ -30,7 +30,7 @@ class SiteController extends Controller { $model = new LoginForm(); if ($model->load($_POST) && $model->login()) { - return $this->redirect(array('site/index')); + return $this->goHome(); } else { return $this->render('login', array( 'model' => $model, @@ -41,7 +41,7 @@ class SiteController extends Controller public function actionLogout() { Yii::$app->user->logout(); - return $this->redirect(array('site/index')); + return $this->goHome(); } public function actionContact() @@ -68,7 +68,7 @@ class SiteController extends Controller $model->setScenario('signup'); if ($model->load($_POST) && $model->save()) { if (Yii::$app->getUser()->login($model)) { - $this->redirect('index'); + return $this->goHome(); } } @@ -84,7 +84,7 @@ class SiteController extends Controller if ($model->load($_POST) && $model->validate()) { if ($this->sendPasswordResetEmail($model->email)) { Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.'); - $this->redirect('index'); + return $this->goHome(); } else { Yii::$app->getSession()->setFlash('error', 'There was an error sending email.'); } @@ -108,7 +108,7 @@ class SiteController extends Controller $model->scenario = 'resetPassword'; if ($model->load($_POST) && $model->save()) { Yii::$app->getSession()->setFlash('success', 'New password was saved.'); - $this->redirect('index'); + return $this->goHome(); } return $this->render('resetPassword', array( diff --git a/apps/basic/controllers/SiteController.php b/apps/basic/controllers/SiteController.php index 0c73873..cd0b3fb 100644 --- a/apps/basic/controllers/SiteController.php +++ b/apps/basic/controllers/SiteController.php @@ -31,7 +31,7 @@ class SiteController extends Controller { $model = new LoginForm(); if ($model->load($_POST) && $model->login()) { - return $this->redirect(array('site/index')); + return $this->goHome(); } else { return $this->render('login', array( 'model' => $model, @@ -42,7 +42,7 @@ class SiteController extends Controller public function actionLogout() { Yii::$app->user->logout(); - return $this->redirect(array('site/index')); + return $this->goHome(); } public function actionContact() diff --git a/apps/basic/views/layouts/main.php b/apps/basic/views/layouts/main.php index 67b74af..03b09fc 100644 --- a/apps/basic/views/layouts/main.php +++ b/apps/basic/views/layouts/main.php @@ -37,7 +37,8 @@ app\config\AppAsset::register($this); Yii::$app->user->isGuest ? array('label' => 'Login', 'url' => array('/site/login')) : array('label' => 'Logout (' . Yii::$app->user->identity->username .')' , 'url' => array('/site/logout')), - ))); + ), + )); NavBar::end(); ?> diff --git a/framework/yii/web/Controller.php b/framework/yii/web/Controller.php index 137b630..b094981 100644 --- a/framework/yii/web/Controller.php +++ b/framework/yii/web/Controller.php @@ -96,14 +96,21 @@ class Controller extends \yii\base\Controller * Redirects the browser to the specified URL. * This method is a shortcut to [[Response::redirect()]]. * - * @param array|string $url the URL to be redirected to. [[Html::url()]] - * will be used to normalize the URL. If the resulting URL is still a relative URL - * (one without host info), the current request host info will be used. + * @param string|array $url the URL to be redirected to. This can be in one of the following formats: + * + * - a string representing a URL (e.g. "http://example.com") + * - a string representing a URL alias (e.g. "@example.com") + * - an array in the format of `array($route, ...name-value pairs...)` (e.g. `array('site/index', 'ref' => 1)`) + * [[Html::url()]] will be used to convert the array into a URL. + * + * Any relative URL will be converted into an absolute one by prepending it with the host info + * of the current request. + * * @param integer $statusCode the HTTP status code. If null, it will use 302 * for normal requests, and [[ajaxRedirectCode]] for AJAX requests. * See [[http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html]] * for details about HTTP status code - * @return Response the response object itself + * @return Response the current response object */ public function redirect($url, $statusCode = null) { @@ -111,6 +118,15 @@ class Controller extends \yii\base\Controller } /** + * Redirects the browser to the home page. + * @return Response the current response object + */ + public function goHome() + { + return Yii::$app->getResponse()->redirect(Yii::$app->getHomeUrl()); + } + + /** * Refreshes the current page. * This method is a shortcut to [[Response::refresh()]]. * @param string $anchor the anchor that should be appended to the redirection URL. diff --git a/framework/yii/web/Response.php b/framework/yii/web/Response.php index a9190b5..ac5fc77 100644 --- a/framework/yii/web/Response.php +++ b/framework/yii/web/Response.php @@ -563,9 +563,17 @@ class Response extends \yii\base\Response * return Yii::$app->getResponse()->redirect($url); * ~~~ * - * @param string $url the URL to be redirected to. This can be a URL or an alias of the URL. - * The URL can be either relative or absolute. If relative, the host info of the current request - * will be prepend to the URL. + * @param string|array $url the URL to be redirected to. This can be in one of the following formats: + * + * - a string representing a URL (e.g. "http://example.com") + * - a string representing a URL alias (e.g. "@example.com") + * - an array in the format of `array($route, ...name-value pairs...)` (e.g. `array('site/index', 'ref' => 1)`). + * Note that the route is with respect to the whole application, instead of relative to a controller or module. + * [[Html::url()]] will be used to convert the array into a URL. + * + * Any relative URL will be converted into an absolute one by prepending it with the host info + * of the current request. + * * @param integer $statusCode the HTTP status code. If null, it will use 302 * for normal requests, and [[ajaxRedirectCode]] for AJAX requests. * See [[http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html]] @@ -574,7 +582,11 @@ class Response extends \yii\base\Response */ public function redirect($url, $statusCode = null) { - $url = Yii::getAlias($url); + if (is_array($url) && isset($url[0])) { + // ensure the route is absolute + $url[0] = '/' . ltrim($url[0], '/'); + } + $url = Html::url($url); if (strpos($url, '/') === 0 && strpos($url, '//') !== 0) { $url = Yii::$app->getRequest()->getHostInfo() . $url; } From 451ff62e3d88507c5d9de4de1f043405a531b55f Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 12 Aug 2013 13:29:37 -0400 Subject: [PATCH 010/131] Added login hint. --- apps/basic/views/site/login.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/basic/views/site/login.php b/apps/basic/views/site/login.php index 15ec52b..9eaccef 100644 --- a/apps/basic/views/site/login.php +++ b/apps/basic/views/site/login.php @@ -26,5 +26,9 @@ $this->params['breadcrumbs'][] = $this->title; +
+ You may login with admin/admin or demo/demo.
+ To modify the username/password, please check out the code app\models\User::$users. +
From 07a04c526e4a724a3378a3ad0ee66b0bc50e6fbd Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 12 Aug 2013 14:11:46 -0400 Subject: [PATCH 011/131] Fixed Menu active item check. --- framework/yii/bootstrap/Nav.php | 9 ++++++++- framework/yii/widgets/Menu.php | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/framework/yii/bootstrap/Nav.php b/framework/yii/bootstrap/Nav.php index 38451d1..186c20a 100644 --- a/framework/yii/bootstrap/Nav.php +++ b/framework/yii/bootstrap/Nav.php @@ -190,7 +190,14 @@ class Nav extends Widget */ protected function isItemActive($item) { - if (isset($item['url']) && is_array($item['url']) && trim($item['url'][0], '/') === $this->route) { + if (isset($item['url']) && is_array($item['url']) && isset($item['url'][0])) { + $route = $item['url'][0]; + if ($route[0] !== '/' && Yii::$app->controller) { + $route = Yii::$app->controller->module->getUniqueId() . '/' . $route; + } + if (ltrim($route, '/') !== $this->route) { + return false; + } unset($item['url']['#']); if (count($item['url']) > 1) { foreach (array_splice($item['url'], 1) as $name => $value) { diff --git a/framework/yii/widgets/Menu.php b/framework/yii/widgets/Menu.php index 40fd479..1d36460 100644 --- a/framework/yii/widgets/Menu.php +++ b/framework/yii/widgets/Menu.php @@ -284,7 +284,14 @@ class Menu extends Widget */ protected function isItemActive($item) { - if (isset($item['url']) && is_array($item['url']) && trim($item['url'][0], '/') === $this->route) { + if (isset($item['url']) && is_array($item['url']) && isset($item['url'][0])) { + $route = $item['url'][0]; + if ($route[0] !== '/' && Yii::$app->controller) { + $route = Yii::$app->controller->module->getUniqueId() . '/' . $route; + } + if (ltrim($route, '/') !== $this->route) { + return false; + } unset($item['url']['#']); if (count($item['url']) > 1) { foreach (array_splice($item['url'], 1) as $name => $value) { From 10e436eeb97854daa62bb2f480e0ac6ff8edd850 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 12 Aug 2013 14:18:08 -0400 Subject: [PATCH 012/131] Fixed bootstrap Modal upgrade. --- framework/yii/bootstrap/Modal.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/framework/yii/bootstrap/Modal.php b/framework/yii/bootstrap/Modal.php index f676273..6d854bc 100644 --- a/framework/yii/bootstrap/Modal.php +++ b/framework/yii/bootstrap/Modal.php @@ -88,6 +88,8 @@ class Modal extends Widget echo $this->renderToggleButton() . "\n"; echo Html::beginTag('div', $this->options) . "\n"; + echo Html::beginTag('div', array('class' => 'modal-dialog')) . "\n"; + echo Html::beginTag('div', array('class' => 'modal-content')) . "\n"; echo $this->renderHeader() . "\n"; echo $this->renderBodyBegin() . "\n"; } @@ -99,6 +101,8 @@ class Modal extends Widget { echo "\n" . $this->renderBodyEnd(); echo "\n" . $this->renderFooter(); + echo "\n" . Html::endTag('div'); // modal-content + echo "\n" . Html::endTag('div'); // modal-dialog echo "\n" . Html::endTag('div'); $this->registerPlugin('modal'); @@ -195,7 +199,7 @@ class Modal extends Widget protected function initOptions() { $this->options = array_merge(array( - 'class' => 'modal hide', + 'class' => 'modal fade', ), $this->options); Html::addCssClass($this->options, 'modal'); From 29077460db6b394f0f3b9b70d2716003ea76757a Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 12 Aug 2013 16:20:44 -0400 Subject: [PATCH 013/131] css fix. --- apps/basic/web/css/site.css | 19 ++++++++++--------- framework/yii/debug/assets/main.css | 7 ++++++- framework/yii/debug/views/default/view.php | 12 +++++++----- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/apps/basic/web/css/site.css b/apps/basic/web/css/site.css index e6db73c..84c46e8 100644 --- a/apps/basic/web/css/site.css +++ b/apps/basic/web/css/site.css @@ -1,19 +1,20 @@ body { - padding-top: 70px; + padding-top: 70px; } .footer { - border-top: 1px solid #ddd; - margin-top: 30px; - padding-top: 15px; - padding-bottom: 30px; + border-top: 1px solid #ddd; + margin-top: 30px; + padding-top: 15px; + padding-bottom: 30px; } .jumbotron { - text-align: center; - background-color: transparent; + text-align: center; + background-color: transparent; } + .jumbotron .btn { - font-size: 21px; - padding: 14px 24px; + font-size: 21px; + padding: 14px 24px; } diff --git a/framework/yii/debug/assets/main.css b/framework/yii/debug/assets/main.css index b60e180..a41c577 100644 --- a/framework/yii/debug/assets/main.css +++ b/framework/yii/debug/assets/main.css @@ -139,5 +139,10 @@ ul.trace { } .callout { margin: 0 0 10px 0; - padding: 5px 10px; + padding: 5px; +} + +.list-group .glyphicon { + float: right; + margin-right: -15px; } diff --git a/framework/yii/debug/views/default/view.php b/framework/yii/debug/views/default/view.php index 8f3af15..c97de9a 100644 --- a/framework/yii/debug/views/default/view.php +++ b/framework/yii/debug/views/default/view.php @@ -28,15 +28,17 @@ $this->title = 'Yii Debugger';
- -
+
+
Date: Tue, 13 Aug 2013 01:16:53 +0400 Subject: [PATCH 014/131] fixes #736 --- apps/advanced/backend/config/AppAsset.php | 1 + apps/advanced/backend/views/layouts/main.php | 63 +++++++++-------- apps/advanced/backend/views/site/index.php | 68 ++++++++++--------- apps/advanced/backend/views/site/login.php | 24 ++++--- apps/advanced/backend/web/css/site.css | 79 +++------------------- apps/advanced/frontend/config/AppAsset.php | 1 + apps/advanced/frontend/views/layouts/main.php | 78 ++++++++++----------- apps/advanced/frontend/views/site/about.php | 12 ++-- apps/advanced/frontend/views/site/contact.php | 41 ++++++----- apps/advanced/frontend/views/site/index.php | 68 ++++++++++--------- apps/advanced/frontend/views/site/login.php | 29 +++++--- .../views/site/requestPasswordResetToken.php | 20 ++++-- .../advanced/frontend/views/site/resetPassword.php | 20 ++++-- apps/advanced/frontend/views/site/signup.php | 24 ++++--- apps/advanced/frontend/web/css/site.css | 79 +++------------------- 15 files changed, 268 insertions(+), 339 deletions(-) diff --git a/apps/advanced/backend/config/AppAsset.php b/apps/advanced/backend/config/AppAsset.php index 90a850d..267e48c 100644 --- a/apps/advanced/backend/config/AppAsset.php +++ b/apps/advanced/backend/config/AppAsset.php @@ -6,6 +6,7 @@ */ namespace backend\config; + use yii\web\AssetBundle; /** diff --git a/apps/advanced/backend/views/layouts/main.php b/apps/advanced/backend/views/layouts/main.php index 9f66a11..5915efb 100644 --- a/apps/advanced/backend/views/layouts/main.php +++ b/apps/advanced/backend/views/layouts/main.php @@ -1,7 +1,8 @@ head(); ?> -
beginBody(); ?> -
-

My Company

- - - -
+ 'My Company', + 'brandUrl' => Yii::$app->homeUrl, + 'options' => array( + 'class' => 'navbar-inverse navbar-fixed-top', + ), + )); + $menuItems = array( + array('label' => 'Home', 'url' => array('/site/index')), + ); + if (Yii::$app->user->isGuest) { + $menuItems[] = array('label' => 'Login', 'url' => array('/site/login')); + } + else { + $menuItems[] = array('label' => 'Logout (' . Yii::$app->user->identity->username .')' , 'url' => array('/site/logout')); + } + echo Nav::widget(array( + 'options' => array('class' => 'navbar-nav pull-right'), + 'items' => $menuItems, + )); + NavBar::end(); + ?> +
isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(), )); ?> +
-
+
+
+

© My Company

+

+
+
- endBody(); ?>
diff --git a/apps/advanced/backend/views/site/index.php b/apps/advanced/backend/views/site/index.php index 158b61c..bc084da 100644 --- a/apps/advanced/backend/views/site/index.php +++ b/apps/advanced/backend/views/site/index.php @@ -2,46 +2,52 @@ /** * @var yii\base\View $this */ -$this->title = 'Welcome'; +$this->title = 'My Yii Application'; ?> -
-

Welcome!

+
-

Cras justo odio, dapibus ac facilisis in, egestas eget quam. Fusce dapibus, tellus ac cursus - commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.

- Get started with Yii -
+
+

Congratulations!

-
+

You have successfully created your Yii-powered application.

- -
-
-

Heading

+

Get started with Yii

+
-

Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris - condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. - Donec sed odio dui.

+ -
-

Heading

+
+
+

Heading

-

Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris - condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. - Donec sed odio dui.

+

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et + dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip + ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu + fugiat nulla pariatur.

-

View details »

-
-
-

Heading

+

Yii Documentation »

+
+
+

Heading

-

Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta - felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum - massa.

+

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et + dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip + ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu + fugiat nulla pariatur.

+ +

Yii Forum »

+
+
+

Heading

+ +

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et + dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip + ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu + fugiat nulla pariatur.

+ +

Yii Extensions »

+
+
-

View details »

- diff --git a/apps/advanced/backend/views/site/login.php b/apps/advanced/backend/views/site/login.php index ea9f456..991d096 100644 --- a/apps/advanced/backend/views/site/login.php +++ b/apps/advanced/backend/views/site/login.php @@ -10,15 +10,21 @@ use yii\widgets\ActiveForm; $this->title = 'Login'; $this->params['breadcrumbs'][] = $this->title; ?> -

title); ?>

+