diff --git a/apps/advanced/backend/views/layouts/main.php b/apps/advanced/backend/views/layouts/main.php index cb41c08621..0a1bf13321 100644 --- a/apps/advanced/backend/views/layouts/main.php +++ b/apps/advanced/backend/views/layouts/main.php @@ -37,7 +37,11 @@ AppAsset::register($this); if (Yii::$app->user->isGuest) { $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']]; } else { - $menuItems[] = ['label' => 'Logout (' . Yii::$app->user->identity->username .')' , 'url' => ['/site/logout']]; + $menuItems[] = [ + 'label' => 'Logout (' . Yii::$app->user->identity->username . ')', + 'url' => ['/site/logout'], + 'linkOptions' => ['data-method' => 'post'] + ]; } echo Nav::widget([ 'options' => ['class' => 'navbar-nav navbar-right'], diff --git a/apps/advanced/common/mail/layouts/html.php b/apps/advanced/common/mail/layouts/html.php index 2e6b615f58..8e2707dc5d 100644 --- a/apps/advanced/common/mail/layouts/html.php +++ b/apps/advanced/common/mail/layouts/html.php @@ -1,10 +1,9 @@ beginPage() ?> diff --git a/apps/advanced/common/tests/_helpers/FixtureHelper.php b/apps/advanced/common/tests/_helpers/FixtureHelper.php index 00c3a1700f..507b60c549 100644 --- a/apps/advanced/common/tests/_helpers/FixtureHelper.php +++ b/apps/advanced/common/tests/_helpers/FixtureHelper.php @@ -32,7 +32,7 @@ class FixtureHelper extends Module * to use in acceptance and functional tests. * @param array $settings */ - public function _beforeSuite($settings = array()) + public function _beforeSuite($settings = []) { $this->loadFixtures(); } @@ -54,5 +54,4 @@ class FixtureHelper extends Module ], ]; } - } diff --git a/apps/advanced/common/tests/_pages/LoginPage.php b/apps/advanced/common/tests/_pages/LoginPage.php index af95ea36a0..5fdf3bc8eb 100644 --- a/apps/advanced/common/tests/_pages/LoginPage.php +++ b/apps/advanced/common/tests/_pages/LoginPage.php @@ -18,5 +18,4 @@ class LoginPage extends BasePage $this->guy->fillField('input[name="LoginForm[password]"]', $password); $this->guy->click('login-button'); } - } diff --git a/apps/advanced/common/tests/unit/models/LoginFormTest.php b/apps/advanced/common/tests/unit/models/LoginFormTest.php index 2ececd6029..9ca277d45b 100644 --- a/apps/advanced/common/tests/unit/models/LoginFormTest.php +++ b/apps/advanced/common/tests/unit/models/LoginFormTest.php @@ -25,7 +25,7 @@ class LoginFormTest extends TestCase $model->username = 'some_username'; $model->password = 'some_password'; - $this->specify('user should not be able to login, when there is no identity' , function () use ($model) { + $this->specify('user should not be able to login, when there is no identity', function () use ($model) { expect('model should not login user', $model->login())->false(); expect('user should not be logged in', Yii::$app->user->isGuest)->true(); }); @@ -52,7 +52,7 @@ class LoginFormTest extends TestCase $model->username = 'demo'; $model->password = 'demo'; - $this->specify('user should be able to login with correct credentials', function() use ($model) { + $this->specify('user should be able to login with correct credentials', function () use ($model) { expect('model should login user', $model->login())->true(); expect('error message should not be set', $model->errors)->hasntKey('password'); expect('user should be logged in', Yii::$app->user->isGuest)->false(); @@ -61,9 +61,8 @@ class LoginFormTest extends TestCase private function mockUser($user) { - $loginForm = $this->getMock('common\models\LoginForm',['getUser']); + $loginForm = $this->getMock('common\models\LoginForm', ['getUser']); $loginForm->expects($this->any())->method('getUser')->will($this->returnValue($user)); return $loginForm; } - } diff --git a/apps/advanced/composer.json b/apps/advanced/composer.json index 53e926f53e..774497124c 100644 --- a/apps/advanced/composer.json +++ b/apps/advanced/composer.json @@ -1,7 +1,7 @@ { "name": "yiisoft/yii2-app-advanced", "description": "Yii 2 Advanced Application Template", - "keywords": ["yii", "framework", "advanced", "application template"], + "keywords": ["yii2", "framework", "advanced", "application template"], "homepage": "http://www.yiiframework.com/", "type": "project", "license": "BSD-3-Clause", diff --git a/apps/advanced/frontend/tests/_pages/SignupPage.php b/apps/advanced/frontend/tests/_pages/SignupPage.php index ba4a9cbb59..0281ac9a5c 100644 --- a/apps/advanced/frontend/tests/_pages/SignupPage.php +++ b/apps/advanced/frontend/tests/_pages/SignupPage.php @@ -20,5 +20,4 @@ class SignupPage extends BasePage } $this->guy->click('signup-button'); } - } diff --git a/apps/advanced/frontend/tests/acceptance/SignupCest.php b/apps/advanced/frontend/tests/acceptance/SignupCest.php index a166f3410f..268ff6bdbd 100644 --- a/apps/advanced/frontend/tests/acceptance/SignupCest.php +++ b/apps/advanced/frontend/tests/acceptance/SignupCest.php @@ -79,5 +79,4 @@ class SignupCest $I->expectTo('see that user logged in'); $I->see('Logout (tester)'); } - } diff --git a/apps/advanced/frontend/tests/functional/SignupCest.php b/apps/advanced/frontend/tests/functional/SignupCest.php index cfef78754a..0409d23318 100644 --- a/apps/advanced/frontend/tests/functional/SignupCest.php +++ b/apps/advanced/frontend/tests/functional/SignupCest.php @@ -79,5 +79,4 @@ class SignupCest $I->expectTo('see that user logged in'); $I->see('Logout (tester)'); } - } diff --git a/apps/advanced/frontend/tests/unit/models/ContactFormTest.php b/apps/advanced/frontend/tests/unit/models/ContactFormTest.php index 23e6288743..a754672f2e 100644 --- a/apps/advanced/frontend/tests/unit/models/ContactFormTest.php +++ b/apps/advanced/frontend/tests/unit/models/ContactFormTest.php @@ -42,7 +42,7 @@ class ContactFormTest extends TestCase expect('email file should exist', file_exists($this->getMessageFile()))->true(); }); - $this->specify('message should contain correct data', function () use($model) { + $this->specify('message should contain correct data', function () use ($model) { $emailMessage = file_get_contents($this->getMessageFile()); expect('email should contain user name', $emailMessage)->contains($model->name); @@ -56,5 +56,4 @@ class ContactFormTest extends TestCase { return Yii::getAlias(Yii::$app->mail->fileTransportPath) . '/testing_message.eml'; } - } diff --git a/apps/advanced/frontend/tests/unit/models/PasswordResetRequestFormTest.php b/apps/advanced/frontend/tests/unit/models/PasswordResetRequestFormTest.php index b736039a29..7591ff32f2 100644 --- a/apps/advanced/frontend/tests/unit/models/PasswordResetRequestFormTest.php +++ b/apps/advanced/frontend/tests/unit/models/PasswordResetRequestFormTest.php @@ -28,14 +28,14 @@ class PasswordResetRequestFormTest extends DbTestCase public function testSendEmailWrongUser() { - $this->specify('no user with such email, message should not be send', function() { + $this->specify('no user with such email, message should not be send', function () { $model = new PasswordResetRequestForm(); $model->email = 'not-existing-email@example.com'; expect('email not send', $model->sendEmail())->false(); }); - $this->specify('user is not active, message should not be send', function() { + $this->specify('user is not active, message should not be send', function () { $model = new PasswordResetRequestForm(); $model->email = $this->user[1]['email']; @@ -52,8 +52,8 @@ class PasswordResetRequestFormTest extends DbTestCase expect('email sent', $model->sendEmail())->true(); expect('user has valid token', $user->password_reset_token)->notNull(); - $this->specify('message has correct format', function() use ($model) { - expect('message file exists', file_exists($this->getMessageFile()))->true(); + $this->specify('message has correct format', function () use ($model) { + expect('message file exists', file_exists($this->getMessageFile()))->true(); $message = file_get_contents($this->getMessageFile()); expect('message "from" is correct', $message)->contains(Yii::$app->params['supportEmail']); @@ -75,5 +75,4 @@ class PasswordResetRequestFormTest extends DbTestCase { return Yii::getAlias(Yii::$app->mail->fileTransportPath) . '/testing_message.eml'; } - } diff --git a/apps/advanced/frontend/tests/unit/models/ResetPasswordFormTest.php b/apps/advanced/frontend/tests/unit/models/ResetPasswordFormTest.php index 763683f70f..b00c2acf35 100644 --- a/apps/advanced/frontend/tests/unit/models/ResetPasswordFormTest.php +++ b/apps/advanced/frontend/tests/unit/models/ResetPasswordFormTest.php @@ -13,13 +13,13 @@ class ResetPasswordFormTest extends DbTestCase public function testResetPassword() { - $this->specify('wrong reset token', function() { - $this->setExpectedException('\Exception','Wrong password reset token.'); + $this->specify('wrong reset token', function () { + $this->setExpectedException('\Exception', 'Wrong password reset token.'); new ResetPasswordForm('notexistingtoken_1391882543'); }); - $this->specify('not correct token', function() { - $this->setExpectedException('yii\base\InvalidParamException','Password reset token cannot be blank.'); + $this->specify('not correct token', function () { + $this->setExpectedException('yii\base\InvalidParamException', 'Password reset token cannot be blank.'); new ResetPasswordForm(''); }); } @@ -33,5 +33,4 @@ class ResetPasswordFormTest extends DbTestCase ], ]; } - } diff --git a/apps/advanced/frontend/tests/unit/models/SignupFormTest.php b/apps/advanced/frontend/tests/unit/models/SignupFormTest.php index 5176baafa2..359a02c186 100644 --- a/apps/advanced/frontend/tests/unit/models/SignupFormTest.php +++ b/apps/advanced/frontend/tests/unit/models/SignupFormTest.php @@ -12,7 +12,7 @@ class SignupFormTest extends DbTestCase public function testCorrectSignup() { - $model = $this->getMock('frontend\models\SignupForm',['validate']); + $model = $this->getMock('frontend\models\SignupForm', ['validate']); $model->expects($this->once())->method('validate')->will($this->returnValue(true)); $model->username = 'some_username'; @@ -28,7 +28,7 @@ class SignupFormTest extends DbTestCase public function testNotCorrectSignup() { - $model = $this->getMock('frontend\models\SignupForm',['validate']); + $model = $this->getMock('frontend\models\SignupForm', ['validate']); $model->expects($this->once())->method('validate')->will($this->returnValue(false)); expect('user should not be created', $model->signup())->null(); @@ -43,5 +43,4 @@ class SignupFormTest extends DbTestCase ], ]; } - } diff --git a/apps/advanced/frontend/views/layouts/main.php b/apps/advanced/frontend/views/layouts/main.php index be8d70d9c4..6e3ae8c4c2 100644 --- a/apps/advanced/frontend/views/layouts/main.php +++ b/apps/advanced/frontend/views/layouts/main.php @@ -41,7 +41,11 @@ AppAsset::register($this); $menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']]; $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']]; } else { - $menuItems[] = ['label' => 'Logout (' . Yii::$app->user->identity->username .')' , 'url' => ['/site/logout']]; + $menuItems[] = [ + 'label' => 'Logout (' . Yii::$app->user->identity->username . ')', + 'url' => ['/site/logout'], + 'linkOptions' => ['data-method' => 'post'] + ]; } echo Nav::widget([ 'options' => ['class' => 'navbar-nav navbar-right'], diff --git a/apps/basic/composer.json b/apps/basic/composer.json index 9990ef7db5..726a7ea93d 100644 --- a/apps/basic/composer.json +++ b/apps/basic/composer.json @@ -1,7 +1,7 @@ { "name": "yiisoft/yii2-app-basic", "description": "Yii 2 Basic Application Template", - "keywords": ["yii", "framework", "basic", "application template"], + "keywords": ["yii2", "framework", "basic", "application template"], "homepage": "http://www.yiiframework.com/", "type": "project", "license": "BSD-3-Clause", diff --git a/apps/basic/mail/layouts/html.php b/apps/basic/mail/layouts/html.php index 2e6b615f58..8e2707dc5d 100644 --- a/apps/basic/mail/layouts/html.php +++ b/apps/basic/mail/layouts/html.php @@ -1,10 +1,9 @@ beginPage() ?> diff --git a/apps/benchmark/composer.json b/apps/benchmark/composer.json index d980f9a136..c8ed58953a 100644 --- a/apps/benchmark/composer.json +++ b/apps/benchmark/composer.json @@ -1,7 +1,7 @@ { "name": "yiisoft/yii2-app-benchmark", "description": "Yii 2 Benchmark Application", - "keywords": ["yii", "framework", "benchmark", "application"], + "keywords": ["yii2", "framework", "benchmark", "application"], "homepage": "http://www.yiiframework.com/", "type": "project", "license": "BSD-3-Clause", diff --git a/build/controllers/ClassmapController.php b/build/controllers/ClassmapController.php index 706435a38a..5fd4e5f162 100644 --- a/build/controllers/ClassmapController.php +++ b/build/controllers/ClassmapController.php @@ -52,7 +52,7 @@ class ClassmapController extends Controller $files = FileHelper::findFiles($root, $options); $map = []; foreach ($files as $file) { - if (($pos = strpos($file, $root)) !== 0) { + if (strpos($file, $root) !== 0) { die("Something wrong: $file\n"); } $path = str_replace('\\', '/', substr($file, strlen($root))); diff --git a/composer.json b/composer.json index d01de3210e..2466074f5a 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "yiisoft/yii2-dev", "description": "Yii PHP Framework Version 2 - Development Package", - "keywords": ["yii", "framework"], + "keywords": ["yii2", "framework"], "homepage": "http://www.yiiframework.com/", "type": "yii2-extension", "license": "BSD-3-Clause", @@ -74,6 +74,7 @@ "lib-pcre": "*", "yiisoft/yii2-composer": "*", "yiisoft/jquery": "~2.0 | ~1.10", + "yiisoft/jquery-pjax": "*", "ezyang/htmlpurifier": "4.6.*", "cebe/markdown": "0.9.*" }, diff --git a/docs/guide/assets.md b/docs/guide/assets.md index 17c6797dbd..ca3b07c842 100644 --- a/docs/guide/assets.md +++ b/docs/guide/assets.md @@ -81,18 +81,26 @@ following way: ```php class LanguageAsset extends AssetBundle { - public $sourcePath = '@app/assets/language'; - public $js = [ - ]; + public $language; + public $sourcePath = '@app/assets/language'; + public $js = [ + ]; - public function init() - { - $this->js[] = 'language-' . Yii::$app->language . '.js'; - parent::init(); - } + public function registerAssetFiles($view) + { + $language = $this->language ? $this->language : Yii::$app->language; + $this->js[] = 'language-' . $language . '.js'; + parent::registerAssetFiles($view); + } } ``` +In order to set language use the following code when registering an asset bundle in a view: + +```php +LanguageAsset::register($this)->language = $language; +``` + Registering asset bundle ------------------------ @@ -114,6 +122,10 @@ To register an asset inside of a widget, the view instance is available as `$thi AppAsset::register($this->view); ``` +> Note: If there is a need to modify third party asset bundles it is recommended to create your own bundles depending + on third party ones and use CSS and JavaScript features to modify behavior instead of editing files directly or + copying them over. + Overriding asset bundles ------------------------ diff --git a/docs/guide/controller.md b/docs/guide/controller.md index 074a31683a..eec7a89263 100644 --- a/docs/guide/controller.md +++ b/docs/guide/controller.md @@ -81,13 +81,16 @@ Routes ------ Each controller action has a corresponding internal route. In our example above `actionIndex` has `site/index` route -and `actionTest` has `site/test` route. In this route `site` is referred to as controller ID while `test` is referred to -as action ID. +and `actionTest` has `site/test` route. In this route `site` is referred to as controller ID while `test` is action ID. By default you can access specific controller and action using the `http://example.com/?r=controller/action` URL. This -behavior is fully customizable. For details refer to [URL Management](url.md). +behavior is fully customizable. For more details please refer to [URL Management](url.md). -If controller is located inside a module its action internal route will be `module/controller/action`. +If a controller is located inside a module, the route of its actions will be in the format of `module/controller/action`. + +A controller can be located under a subdirectory of the controller directory of an application or module. The route +will be prefixed with the corresponding directory names. For example, you may have a `UserController` under `controllers/admin`. +The route of its `actionIndex` would be `admin/user/index`, and `admin/user` would be the controller ID. In case module, controller or action specified isn't found Yii will return "not found" page and HTTP status code 404. diff --git a/docs/guide/module-debug.md b/docs/guide/module-debug.md index 91da33af9f..916101c105 100644 --- a/docs/guide/module-debug.md +++ b/docs/guide/module-debug.md @@ -110,7 +110,7 @@ class ViewsPanel extends Panel { parent::init(); Event::on(View::className(), View::EVENT_BEFORE_RENDER, function (ViewEvent $event) { - $this->_viewFiles[] = $event->viewFile; + $this->_viewFiles[] = $event->sender->getViewFile(); }); } diff --git a/docs/guide/theming.md b/docs/guide/theming.md index e627f7cb60..037e70c8f9 100644 --- a/docs/guide/theming.md +++ b/docs/guide/theming.md @@ -1,7 +1,12 @@ Theming ======= -TBD +A theme is a directory of view and layout files. Each file of the theme overrides corresponding file of an application +when rendered. A single application may use multiple themes and each may provide totally different experience. At any +time only one theme can be active. + +> Note: Themes usually do not meant to be redistributed since views are too application specific. If you want to + redistribute customized look and feel consider CSS and JavaScript files in form of [asset bundles](assets.md) instead. Configuring current theme ------------------------- @@ -18,4 +23,27 @@ be in your application config file: ], ], ], -``` \ No newline at end of file +``` + +In the above `pathMap` defines where to look for view files while `baseUrl` defines base URL for resources referenced +from these files. For example, if `pathMap` is `['/web/views' => '/web/themes/basic']`, then the themed version +for a view file `/web/views/site/index.php` will be `/web/themes/basic/site/index.php`. + +Using multiple paths +-------------------- + +It is possible to map a single path to multiple paths. For example, + +```php +'pathMap' => [ + '/web/views' => [ + '/web/themes/christmas', + '/web/themes/basic', + ], +] +``` + +In this case, the view will be searched in `/web/themes/christmas/site/index.php` then if it's not found it will check +`/web/themes/basic/site/index.php`. If there's no view there as well application view will be used. + +This ability is especially useful if you want to temporary or conditionally override some views. diff --git a/docs/guide/upgrade-from-v1.md b/docs/guide/upgrade-from-v1.md index 92dc8680d8..612eeab894 100644 --- a/docs/guide/upgrade-from-v1.md +++ b/docs/guide/upgrade-from-v1.md @@ -329,9 +329,9 @@ public function behaviors() 'class' => 'yii\web\AccessControl', 'rules' => [ ['allow' => true, 'actions' => ['admin'], 'roles' => ['@']], - ), - ), - ); + ], + ], + ]; } ``` diff --git a/extensions/apidoc/composer.json b/extensions/apidoc/composer.json index 276ceb1552..6c0c5cee30 100644 --- a/extensions/apidoc/composer.json +++ b/extensions/apidoc/composer.json @@ -1,7 +1,7 @@ { "name": "yiisoft/yii2-apidoc", "description": "API Documentation generator for the Yii framework 2.0", - "keywords": ["yii", "phpdoc", "apidoc", "api", "documentation"], + "keywords": ["yii2", "phpdoc", "apidoc", "api", "documentation"], "type": "yii2-extension", "license": "BSD-3-Clause", "support": { diff --git a/extensions/apidoc/templates/html/views/eventDetails.php b/extensions/apidoc/templates/html/views/eventDetails.php index 15a67517d2..46fc5bd8b9 100644 --- a/extensions/apidoc/templates/html/views/eventDetails.php +++ b/extensions/apidoc/templates/html/views/eventDetails.php @@ -18,7 +18,7 @@ ArrayHelper::multisort($events, 'name');
= ' echo __FILE__; ?>
.
+ the file = '=' ?> __FILE__; ?>
.
diff --git a/extensions/gii/generators/crud/templates/views/create.php b/extensions/gii/generators/crud/templates/views/create.php
index 68d08ba7e9..72a1f8dadc 100644
--- a/extensions/gii/generators/crud/templates/views/create.php
+++ b/extensions/gii/generators/crud/templates/views/create.php
@@ -26,8 +26,8 @@ $this->params['breadcrumbs'][] = $this->title;
= "= " ?>Html::a('Update', ['update', = $urlParams ?>], ['class' => 'btn btn-primary']) ?> - = "echo Html::a('Delete', ['delete', = $urlParams ?>], [ + = "= " ?>Html::a('Delete', ['delete', = $urlParams ?>], [ 'class' => 'btn btn-danger', 'data' => [ 'confirm' => Yii::t('app', 'Are you sure to delete this item?'), 'method' => 'post', ], - ]); ?> + ]) ?>
- = "echo DetailView::widget([ + = "= " ?>DetailView::widget([ 'model' => $model, 'attributes' => [ getTableSchema()) === false) { } ?> ], - ]); ?> + ]) ?> diff --git a/extensions/gii/generators/model/Generator.php b/extensions/gii/generators/model/Generator.php index 538637cc75..893cd7facc 100644 --- a/extensions/gii/generators/model/Generator.php +++ b/extensions/gii/generators/model/Generator.php @@ -471,7 +471,7 @@ class Generator extends \yii\gii\Generator */ public function validateTableName() { - if (($pos = strpos($this->tableName, '*')) !== false && substr($this->tableName, -1) !== '*') { + if (strpos($this->tableName, '*') !== false && substr($this->tableName, -1) !== '*') { $this->addError('tableName', 'Asterisk is only allowed as the last character.'); return; } diff --git a/extensions/gii/views/default/view/files.php b/extensions/gii/views/default/view/files.php index 947c8f87bf..fbe5e69cfd 100644 --- a/extensions/gii/views/default/view/files.php +++ b/extensions/gii/views/default/view/files.php @@ -81,7 +81,14 @@ use yii\gii\CodeFile;