Различия
Показаны различия между двумя версиями страницы.
Предыдущая версия справа и слева Предыдущая версия Следующая версия | Предыдущая версия | ||
yii2:docs [2017/01/04 21:54] – mirocow | yii2:docs [2019/04/18 13:17] (текущий) – [Active Record] mirocow | ||
---|---|---|---|
Строка 2: | Строка 2: | ||
====== Документация по Yii 2 Framework ====== | ====== Документация по Yii 2 Framework ====== | ||
- | |||
- | |||
===== Configuration ===== | ===== Configuration ===== | ||
Строка 36: | Строка 34: | ||
]; | ]; | ||
</ | </ | ||
+ | ===== URL Management ===== | ||
- | ===== PHPUnit ===== | + | <code php> |
- | + | echo \Yii:: | |
- | добавить в конфигуратор композера composer.json | + | // /index.php/ |
- | <code> | + | echo \Yii:: |
- | { | + | // / |
- | " | + | echo \Yii:: |
- | " | + | // http://www.example.com/ |
- | } | + | |
- | } | + | |
</ | </ | ||
- | |||
- | * php composer.phar update | ||
- | * php vendor/ | ||
- | |||
- | ===== URL Management ===== | ||
<code php> | <code php> | ||
Строка 66: | Строка 58: | ||
</ | </ | ||
- | ===== Request ===== | + | ==== Конфигурация |
- | + | ||
- | ==== GET ==== | + | |
<code php> | <code php> | ||
- | Yii:: | + | <?php |
- | Yii:: | + | return [ |
- | Yii:: | + | // ... |
- | Yii:: | + | 'components' => [ |
- | </ | + | 'urlManager' |
- | ==== POST ==== | + | 'enablePrettyUrl' => true, |
- | + | ' | |
- | <code php> | + | ' |
- | Yii:: | + | ' |
- | Yii:: | + | |
- | Yii:: | + | '<action:(login|logout|about)>' => 'site/<action>', |
- | Yii:: | + | |
- | </ | + | // ... |
- | + | ||
- | ===== View ===== | + | ['class' => 'app\components\CarUrlRule', 'connectionID' => 'db', ...], |
- | + | ], | |
- | ==== CSS ==== | + | |
- | + | ||
- | <code php> | + | |
- | $this-> | + | |
- | </code> | + | |
- | ==== JS ==== | + | |
- | + | ||
- | === Вставка кода внутри представления === | + | |
- | + | ||
- | В примере производится вставка JS кода из assets c применением переменной в скрипте JS_FABRIC_CAR_URL | + | |
- | <code php> | + | |
- | $this = Yii::$app->view; | + | |
- | </ | + | |
- | + | ||
- | <code php> | + | |
- | <?php | + | |
- | $this-> | + | |
- | $publish | + | |
- | $this-> | + | |
- | ?> | + | |
- | </code> | + | |
- | + | ||
- | === assetManager === | + | |
- | + | ||
- | <code php> | + | |
- | 'components' => [ | + | |
- | | + | |
- | | + | |
- | | + | |
], | ], | ||
- | ], | + | ]; |
</ | </ | ||
+ | ==== Url ==== | ||
- | * forceCopy - Включает постоянное обновление асетов | + | === yii\helpers\Url:: |
- | + | ||
- | ==== Добавление csrfToken в Ajax запрос (Yii2) ==== | + | |
- | + | ||
- | === через ajaxSetup === | + | |
- | + | ||
- | + | ||
- | <code php> | + | |
- | $js_global_variables = ' | + | |
- | $.ajaxSetup({ | + | |
- | data: ' . \yii\helpers\Json:: | + | |
- | \yii:: | + | |
- | ]) . ' | + | |
- | });' . PHP_EOL; | + | |
- | $this-> | + | |
- | </ | + | |
- | + | ||
- | === или через header === | + | |
- | + | ||
- | + | ||
- | <code php> | + | |
- | $js_global_variables = ' | + | |
- | $.ajaxPrefilter(function( options ) { | + | |
- | if ( !options.beforeSend) { | + | |
- | options.beforeSend = function (xhr) { | + | |
- | xhr.setRequestHeader(" | + | |
- | } | + | |
- | } | + | |
- | });' . PHP_EOL; | + | |
- | $this-> | + | |
- | </ | + | |
- | + | ||
- | === или через JQuery === | + | |
- | + | ||
- | + | ||
- | <code js> | + | |
- | $.ajax({ | + | |
- | url: ' | + | |
- | type: ' | + | |
- | data: {payload: payload, _csrf: yii.getCsrfToken()}, | + | |
- | dataType: ' | + | |
- | }).success(function(response) { | + | |
- | }); | + | |
- | </ | + | |
- | + | ||
- | ===== Виджеты / Widgets ===== | + | |
- | + | ||
- | * [[yii2: | + | |
- | * | + | |
- | + | ||
- | ===== Url ===== | + | |
- | + | ||
- | + | ||
- | ===== yii\helpers\Url:: | + | |
<code php> | <code php> | ||
Строка 189: | Строка 99: | ||
</ | </ | ||
- | ===== yii\helpers\Url:: | + | === yii\helpers\Url:: |
<code php> | <code php> | ||
Строка 219: | Строка 129: | ||
Примеры использоватия можно глянуть в тестах https:// | Примеры использоватия можно глянуть в тестах https:// | ||
- | ===== yii\helpers\Html:: | + | === yii\helpers\Html:: |
<code php> | <code php> | ||
Строка 239: | Строка 149: | ||
Примеры использоватия можно глянуть в тестах https:// | Примеры использоватия можно глянуть в тестах https:// | ||
- | ===== createUrl | + | ==== createUrl ==== |
<code php> | <code php> | ||
Строка 254: | Строка 164: | ||
echo $this-> | echo $this-> | ||
</ | </ | ||
- | ===== createAbsoluteUrl (old) ===== | + | |
+ | === createAbsoluteUrl (old) === | ||
Усли $this - это yii\web\Controller | Усли $this - это yii\web\Controller | ||
Строка 266: | Строка 177: | ||
</ | </ | ||
- | вместо старых методов нада использовать **yii\helpers:: | + | вместо старых методов надо использовать **yii\helpers:: |
Усли $this - это yii\web\Controller | Усли $this - это yii\web\Controller | ||
Строка 276: | Строка 187: | ||
</ | </ | ||
- | вместо старых методов нада использовать **yii\helpers:: | + | вместо старых методов надо использовать **yii\helpers:: |
- | ==== urlManager | + | ==== Request |
+ | === GET === | ||
<code php> | <code php> | ||
- | echo \Yii:: | + | Yii:: |
- | // / | + | Yii:: |
- | echo \Yii:: | + | Yii::$app->request-> |
- | // / | + | Yii:: |
- | echo \Yii:: | + | |
- | // http:// | + | |
</ | </ | ||
- | == Custom | + | === POST === |
<code php> | <code php> | ||
- | <?php | + | Yii:: |
- | return [ | + | Yii:: |
- | // ... | + | Yii:: |
- | | + | Yii:: |
- | 'urlManager' => [ | + | </ |
- | ' | + | |
- | ' | + | ===== View ===== |
- | ' | + | |
- | ' | + | ==== CSS ==== |
- | | + | |
- | '<action:(login|logout|about)>' => 'site/<action>', | + | <code php> |
- | + | $this-> | |
- | // ... | + | </ |
- | + | ||
- | ['class' => 'app\components\CarUrlRule', 'connectionID' => 'db', ...], | + | ==== JS ==== |
- | ], | + | |
- | | + | <code php> |
+ | $this-> | ||
+ | </ | ||
+ | |||
+ | === Вставка кода внутри представления === | ||
+ | |||
+ | В примере производится вставка JS кода из assets c применением переменной в скрипте JS_FABRIC_CAR_URL | ||
+ | <code php> | ||
+ | $this = Yii::$app->view; | ||
+ | </ | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | $this-> | ||
+ | $publish | ||
+ | $this-> | ||
+ | ?> | ||
+ | </code> | ||
+ | |||
+ | ==== assetManager ==== | ||
+ | |||
+ | <code php> | ||
+ | 'components' => [ | ||
+ | | ||
+ | | ||
+ | | ||
], | ], | ||
- | ]; | + | ], |
</ | </ | ||
- | ===== Controller ===== | + | * forceCopy - Включает постоянное обновление асетов |
- | ==== Как программно вызвать контроллер? ==== | + | === через ajaxSetup |
+ | |||
+ | Добавление csrfToken | ||
<code php> | <code php> | ||
- | $className | + | $js_global_variables |
- | $controller | + | $.ajaxSetup({ |
+ | data: ' . \yii\helpers\Json:: | ||
+ | | ||
+ | ]) . ' | ||
+ | });' . PHP_EOL; | ||
+ | $this-> | ||
</ | </ | ||
- | ===== yii\helpers\Html (old) ===== | + | или через header |
<code php> | <code php> | ||
- | // [' | + | $js_global_variables |
- | Html::a("Log in here", | + | $.ajaxPrefilter(function( options ) { |
- | Html::url([" | + | if ( !options.beforeSend) { |
+ | options.beforeSend | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | });' . PHP_EOL; | ||
+ | $this-> | ||
</ | </ | ||
- | **Подробно** https:// | + | или через JQuery |
+ | |||
+ | <code js> | ||
+ | $.ajax({ | ||
+ | url: ' | ||
+ | type: ' | ||
+ | data: {payload: payload, _csrf: yii.getCsrfToken()}, | ||
+ | dataType: ' | ||
+ | }).success(function(response) { | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | ==== Form ==== | ||
+ | |||
+ | * [[yii2: | ||
+ | * [[yii2: | ||
+ | |||
+ | **Подробно** https:// | ||
===== Ajax ===== | ===== Ajax ===== | ||
Строка 389: | Строка 354: | ||
<?php Pjax:: | <?php Pjax:: | ||
</ | </ | ||
- | ===== User ===== | ||
- | ===== RBAC ===== | + | ===== Виджеты / Widgets |
- | * [[yii2:user:rbac|RBAC]] | + | * [[yii2:widgets:masked-input|]] - http:// |
- | **Подробно** https://github.com/yiisoft/ | + | ===== Model / AR / DAO / Запросы к БД ===== |
- | ====== Access ===== | + | Как получить модель из модуля |
<code php> | <code php> | ||
- | ' | + | $user |
- | ' | + | $profile |
- | ' | + | |
- | [ | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ], | + | |
- | [ | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | | + | |
- | } | + | |
- | ], | + | |
- | ], | + | |
- | ], | + | |
</ | </ | ||
+ | ==== Active Record ==== | ||
+ | <code php> | ||
+ | class Post extends ActiveRecord | ||
+ | { | ||
+ | public function getCreator() | ||
+ | { | ||
+ | return $this-> | ||
+ | } | ||
+ | public function getComments() | ||
+ | { | ||
+ | return $this-> | ||
+ | } | ||
+ | public function getTrustComments($isTrust = true) | ||
+ | { | ||
+ | return $this-> | ||
+ | -> | ||
+ | ': | ||
+ | ]) | ||
+ | -> | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | <code php> | ||
+ | $price = PriceItem:: | ||
+ | -> | ||
+ | -> | ||
+ | [' | ||
+ | ['>', | ||
+ | ])-> | ||
+ | </ | ||
- | ===== Model ===== | + | <code php> |
+ | // we receive an ActiveQuery instance | ||
+ | $query | ||
+ | |||
+ | // all posts | ||
+ | $posts | ||
+ | |||
+ | // looking for all the posts with a condition | ||
+ | $posts | ||
+ | -> | ||
+ | -> | ||
+ | -> | ||
+ | |||
+ | // looking for a post | ||
+ | $post = $query | ||
+ | | ||
+ | | ||
+ | |||
+ | // or easier: " | ||
+ | $post = Post:: | ||
+ | |||
+ | // having transmitted to the factory method not a massive, but a number equivalent to the primary key search | ||
+ | $post = Post:: | ||
+ | | ||
+ | | ||
+ | |||
+ | // we index the result to a necessary attribute | ||
+ | $posts = $query-> | ||
+ | |||
+ | // the result as an array | ||
+ | $posts = $query-> | ||
+ | </ | ||
- | ==== modules/user ==== | + | <code php> |
+ | User:: | ||
+ | User:: | ||
+ | </ | ||
+ | |||
+ | === Ключи в эллементах коллекции AR === | ||
<code php> | <code php> | ||
- | | + | $query = SparesCategory::find()->where([' |
- | $profile = Yii::$app->getModule(" | + | $query->indexBy = function($row){ // Ключ в который будет помещена возвращаемая модель |
+ | return $row->id; | ||
+ | }; | ||
+ | $categories = $query-> | ||
+ | </ | ||
- | if($user->load($_POST)){ | + | <code php> |
- | if ($user-> | + | $quey = CarMark:: |
- | $profile-> | + | |
- | | + | })->all(); |
- | } | + | |
- | } | + | |
</ | </ | ||
- | * https:// | + | === Создание модели из возвращаемы данных Command (с помощью populateRecord()) === |
- | * https:// | + | |
- | ==== Active Record | + | <code php> |
+ | $sql = " | ||
+ | LEFT JOIN tbl_form_spares_category fc ON fc.category_id | ||
+ | WHERE fc.form_id | ||
+ | $select_marks | ||
+ | ': | ||
+ | ': | ||
+ | ])-> | ||
+ | |||
+ | foreach($marks as $row){ | ||
+ | |||
+ | // Only yii2 alpha | ||
+ | // | ||
+ | |||
+ | $mark = new SparesCategoryForm; | ||
+ | SparesCategoryForm:: | ||
+ | |||
+ | |||
+ | if(isset($mark-> | ||
+ | |||
+ | // do somethig | ||
+ | |||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | * [[Activedataprovider|Activedataprovider]] | ||
+ | * [[SqlDataProvider|SqlDataProvider]] | ||
+ | * [[ArrayDataProvider|ArrayDataProvider]] | ||
==== Join ==== | ==== Join ==== | ||
Строка 497: | Строка 540: | ||
{ | { | ||
return [ | return [ | ||
- | [' | + | |
- | ' | + | |
- | // specifies in which scenario(s) this rule is active. | + | ' |
- | // if not given, it means it is active in all scenarios | + | // specifies in which scenario(s) this rule is active. |
- | ' | + | // if not given, it means it is active in all scenarios |
- | // the following name-value pairs will be used | + | ' |
- | // to initialize the validator properties | + | // the following name-value pairs will be used |
- | ' | + | // to initialize the validator properties |
- | ' | + | ' |
- | // ... | + | ' |
+ | // ... | ||
+ | | ||
+ | [ | ||
+ | [' | ||
+ | ' | ||
+ | | ||
+ | // if not given, it means it is active in all scenarios | ||
+ | ' | ||
+ | // the following name-value pairs will be used | ||
+ | // to initialize the validator properties | ||
+ | ' | ||
+ | ' | ||
+ | // ... | ||
+ | ], | ||
]; | ]; | ||
} | } | ||
Строка 548: | Строка 605: | ||
* **Список базовых валидаторов: | * **Список базовых валидаторов: | ||
- | ===== Scenario | + | ==== Scenario ==== |
<code php> | <code php> | ||
Строка 582: | Строка 639: | ||
**Подробно** https:// | **Подробно** https:// | ||
- | ===== Connection/ | + | ==== Relation |
- | ==== Connection | + | <code php> |
+ | class Customer extends \yii\db\ActiveRecord | ||
+ | { | ||
+ | // | ||
+ | public function getOrders() | ||
+ | { | ||
+ | return $this-> | ||
+ | } | ||
+ | |||
+ | // | ||
+ | public function getBigOrders($threshold | ||
+ | { | ||
+ | return $this-> | ||
+ | -> | ||
+ | -> | ||
+ | } | ||
+ | |||
+ | // Вытащить данные из таблицы модели Item, используя связи из таблицы tbl_order_item | ||
+ | public function getItems() | ||
+ | { | ||
+ | // Получить данные через таблицу tbl_order_item | ||
+ | return $this-> | ||
+ | -> | ||
+ | } | ||
+ | |||
+ | // | ||
+ | public static function olderThan($query, | ||
+ | { | ||
+ | $query-> | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code php> | ||
+ | $customer = Customer:: | ||
+ | $orders = $customer-> | ||
+ | $orders = $customer-> | ||
+ | $customers = Customer:: | ||
+ | </ | ||
+ | |||
+ | <code php> | ||
+ | $customer = Customer:: | ||
+ | $order = new Order(); | ||
+ | $order-> | ||
+ | $customer-> | ||
+ | </ | ||
+ | |||
+ | ==== Events ==== | ||
+ | |||
+ | <code php> | ||
+ | class Post extends ActiveRecord | ||
+ | { | ||
+ | public function init() | ||
+ | { | ||
+ | $this-> | ||
+ | // отменяем действие | ||
+ | $event-> | ||
+ | }); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code php> | ||
+ | $component-> | ||
+ | </ | ||
+ | ==== Как получить SQL и Параметры из ActiveQuery ==== | ||
+ | |||
+ | <code php> | ||
+ | $query = Post:: | ||
+ | |||
+ | // SQL | ||
+ | echo $query-> | ||
+ | |||
+ | // Params: | ||
+ | print_r($query-> | ||
+ | </ | ||
+ | ==== Объекты доступа к данным (Data Access Objects, DAO) ==== | ||
+ | |||
+ | === Соеденение | ||
<code php> | <code php> | ||
Строка 594: | Строка 729: | ||
* https:// | * https:// | ||
- | ===== Command ===== | + | === Методы запроса |
* queryOne() | * queryOne() | ||
Строка 603: | Строка 738: | ||
**Подробно** | **Подробно** | ||
+ | |||
+ | == createCommand == | ||
<code php> | <code php> | ||
Строка 643: | Строка 780: | ||
</ | </ | ||
- | ==== Query Builder and Query ==== | + | ==== Построитель запросов (Query Builder and Query) ==== |
<code php> | <code php> | ||
Строка 696: | Строка 833: | ||
* https:// | * https:// | ||
- | ===== Transactions | + | ==== Transactions ==== |
<code php> | <code php> | ||
Строка 710: | Строка 847: | ||
</ | </ | ||
- | ===== Active Record ===== | + | ==== Batch ==== |
- | <code php> | + | === Batch === |
- | class Post extends ActiveRecord | + | |
- | { | + | |
- | public function getCreator() | + | |
- | { | + | |
- | return $this-> | + | |
- | } | + | |
- | public function getComments() | + | |
- | { | + | |
- | return $this-> | + | |
- | } | + | |
- | public function getTrustComments($isTrust = true) | + | |
- | { | + | |
- | return $this-> | + | |
- | -> | + | |
- | ': | + | |
- | )) | + | |
- | -> | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | <code php> | + | |
- | $price = PriceItem:: | + | |
- | -> | + | |
- | -> | + | |
- | [' | + | |
- | ['>', | + | |
- | ])-> | + | |
- | </ | + | |
- | + | ||
- | <code php> | + | |
- | // we receive an ActiveQuery instance | + | |
- | $query = Post:: | + | |
- | + | ||
- | // all posts | + | |
- | $posts = $query-> | + | |
- | + | ||
- | // looking for all the posts with a condition | + | |
- | $posts = $query | + | |
- | -> | + | |
- | -> | + | |
- | -> | + | |
- | + | ||
- | // looking for a post | + | |
- | $post = $query | + | |
- | | + | |
- | | + | |
- | + | ||
- | // or easier: " | + | |
- | $post = Post:: | + | |
- | + | ||
- | // having transmitted to the factory method not a massive, but a number equivalent to the primary key search | + | |
- | $post = Post:: | + | |
- | | + | |
- | | + | |
- | + | ||
- | // we index the result to a necessary attribute | + | |
- | $posts = $query-> | + | |
- | + | ||
- | // the result as an array | + | |
- | $posts = $query-> | + | |
- | </ | + | |
- | + | ||
- | ===== Как получить SQL и Параметры из ActiveQuery ===== | + | |
- | + | ||
- | <code php> | + | |
- | $query = Post:: | + | |
- | + | ||
- | // SQL | + | |
- | echo $query-> | + | |
- | + | ||
- | // Params: | + | |
- | print_r($query-> | + | |
- | </ | + | |
- | + | ||
- | ==== Batch ==== | + | |
Строка 818: | Строка 879: | ||
Yii:: | Yii:: | ||
</ | </ | ||
- | ==== Each ==== | + | |
+ | === Each === | ||
<code php> | <code php> | ||
Строка 830: | Строка 892: | ||
</ | </ | ||
- | ==== Ключи в эллементах коллекции AR ==== | + | ===== Controller ===== |
- | == AR == | + | ==== Как программно вызвать контроллер? |
<code php> | <code php> | ||
- | $query = SparesCategory:: | + | $className |
- | $query-> | + | $controller |
- | return $row-> | + | |
- | }; | + | |
- | $categories = $query-> | + | |
- | </ | + | |
- | + | ||
- | <code php> | + | |
- | $quey = CarMark::find()-> | + | |
- | return | + | |
- | })->all(); | + | |
</ | </ | ||
- | ==== Создание модели из возвращаемы данных Command | + | ==== yii\helpers\Html |
<code php> | <code php> | ||
- | $sql = " | + | // [' |
- | LEFT JOIN tbl_form_spares_category fc ON fc.category_id | + | Html::a("Log in here", [" |
- | WHERE fc.form_id = :form_id AND fc.category_id = :category_id"; | + | Html::url([" |
- | $select_marks = Yii:: | + | |
- | ': | + | |
- | ': | + | |
- | | + | |
- | + | ||
- | foreach($marks as $row){ | + | |
- | + | ||
- | // Only yii2 alpha | + | |
- | //$mark = SparesCategoryForm::create($row); | + | |
- | + | ||
- | $mark = new SparesCategoryForm; | + | |
- | SparesCategoryForm:: | + | |
- | + | ||
- | + | ||
- | if(isset($mark-> | + | |
- | + | ||
- | // do somethig | + | |
- | + | ||
- | } | + | |
- | } | + | |
</ | </ | ||
- | + | **Подробно** https:// | |
- | + | ||
- | * [[Activedataprovider|Activedataprovider]] | + | |
- | * [[SqlDataProvider|SqlDataProvider]] | + | |
- | * [[ArrayDataProvider|ArrayDataProvider]] | + | |
- | + | ||
- | **Подробно: | + | |
- | + | ||
- | ===== Relation ===== | + | |
- | + | ||
- | <code php> | + | |
- | class Customer extends \yii\db\ActiveRecord | + | |
- | { | + | |
- | // | + | |
- | public function getOrders() | + | |
- | { | + | |
- | return $this-> | + | |
- | } | + | |
- | + | ||
- | // | + | |
- | public function getBigOrders($threshold = 100) | + | |
- | { | + | |
- | return $this-> | + | |
- | -> | + | |
- | -> | + | |
- | } | + | |
- | + | ||
- | // Вытащить данные из таблицы модели Item, используя связи из таблицы tbl_order_item | + | |
- | public function getItems() | + | |
- | { | + | |
- | // Получить данные через таблицу tbl_order_item | + | |
- | return $this-> | + | |
- | -> | + | |
- | } | + | |
- | + | ||
- | // | + | |
- | public static function olderThan($query, | + | |
- | { | + | |
- | $query-> | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | <code php> | + | |
- | $customer = Customer:: | + | |
- | $orders = $customer-> | + | |
- | $orders = $customer-> | + | |
- | $customers = Customer:: | + | |
- | </ | + | |
- | + | ||
- | <code php> | + | |
- | $customer = Customer:: | + | |
- | $order = new Order(); | + | |
- | $order-> | + | |
- | $customer-> | + | |
- | </ | + | |
- | + | ||
- | ===== Events ===== | + | |
- | + | ||
- | <code php> | + | |
- | class Post extends ActiveRecord | + | |
- | { | + | |
- | public function init() | + | |
- | { | + | |
- | $this-> | + | |
- | // отменяем действие | + | |
- | $event-> | + | |
- | }); | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | <code php> | + | |
- | $component-> | + | |
- | </ | + | |
- | + | ||
- | ===== Components ===== | + | |
- | + | ||
- | Создание объекта компанента | + | |
- | <code php> | + | |
- | $object = Yii:: | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ), $param1, $param2); | + | |
- | </ | + | |
- | + | ||
- | ===== Theme ===== | + | |
- | + | ||
- | <code php> | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ), | + | |
- | ), | + | |
- | </ | + | |
- | + | ||
- | ===== Form ===== | + | |
- | + | ||
- | * [[yii2: | + | |
- | * [[yii2: | + | |
- | + | ||
- | **Подробно** https:// | + | |
- | + | ||
- | ===== Assets ===== | + | |
- | + | ||
- | + | ||
- | ===== Console ===== | + | |
- | + | ||
- | ===== IsConsole ===== | + | |
- | + | ||
- | <code php> | + | |
- | | + | |
- | // | + | |
- | } | + | |
- | </ | + | |
===== Module ===== | ===== Module ===== | ||
Строка 1022: | Строка 939: | ||
</ | </ | ||
- | + | ==== Helpers ==== | |
- | + | ||
- | ===== Helpers | + | |
* https:// | * https:// | ||
- | ===== Behaviors/ | + | ==== Behaviors/ |
<code php> | <code php> | ||
public function behaviors() | public function behaviors() | ||
{ | { | ||
- | | + | |
- | ' | + | ' |
- | ' | + | ' |
- | ' | + | ' |
- | array(' | + | array(' |
- | array(' | + | array(' |
- | ), | + | ), |
- | ), | + | ), |
- | ); | + | ); |
} | } | ||
</ | </ | ||
- | ===== Статьи ===== | + | ==== Behaviors/Date ==== |
- | + | ||
- | + | ||
- | * http:// | + | |
- | + | ||
- | + | ||
- | ===== Локализация - i18N/intl ===== | + | |
- | + | ||
- | apt=get install php5-intl | + | |
- | | + | |
+ | <code php> | ||
+ | public function behaviors() { | ||
+ | return [ | ||
+ | [ | ||
+ | ' | ||
+ | ' | ||
+ | //' | ||
+ | ' | ||
+ | ], | ||
+ | ]; | ||
+ | } | ||
+ | </ | ||
===== Session ===== | ===== Session ===== | ||
Строка 1063: | Строка 981: | ||
</ | </ | ||
- | ===== setFlash | + | ==== setFlash ==== |
В контролере | В контролере | ||
Строка 1104: | Строка 1022: | ||
| Sweetalert | | Sweetalert | ||
| Toastr | | Toastr | ||
+ | |||
+ | |||
+ | ===== Console ===== | ||
+ | |||
+ | ==== IsConsole ==== | ||
+ | |||
+ | <code php> | ||
+ | | ||
+ | // | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Params / Параметры ==== | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | |||
+ | namespace console\controllers; | ||
+ | |||
+ | use yii\console\Controller; | ||
+ | |||
+ | class QueueController extends Controller | ||
+ | { | ||
+ | public $pid_file = ''; | ||
+ | |||
+ | public function __get($name) | ||
+ | { | ||
+ | $name = str_replace(' | ||
+ | |||
+ | return $this-> | ||
+ | } | ||
+ | |||
+ | public function __set($name, | ||
+ | { | ||
+ | $name = str_replace(' | ||
+ | |||
+ | $this-> | ||
+ | } | ||
+ | |||
+ | |||
+ | public function options($actionID) | ||
+ | { | ||
+ | return [' | ||
+ | } | ||
+ | |||
+ | public function actionRun() | ||
+ | { | ||
+ | |||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== User ===== | ||
+ | |||
+ | ==== RBAC ==== | ||
+ | |||
+ | * [[yii2: | ||
+ | |||
+ | **Подробно** https:// | ||
+ | |||
+ | ==== Access ==== | ||
+ | |||
+ | <code php> | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | [ | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ], | ||
+ | [ | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | return \Yii:: | ||
+ | } | ||
+ | ], | ||
+ | ], | ||
+ | ], | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Components ===== | ||
+ | |||
+ | Создание объекта компанента | ||
+ | <code php> | ||
+ | $object = Yii:: | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ), $param1, $param2); | ||
+ | </ | ||
+ | |||
+ | ===== Theme ===== | ||
+ | |||
+ | <code php> | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ), | ||
+ | ), | ||
+ | </ | ||
===== Cache ===== | ===== Cache ===== | ||
Строка 1129: | Строка 1152: | ||
* [[yii\caching\TagDependency]]: | * [[yii\caching\TagDependency]]: | ||
- | ===== Кэширование запросов | + | ==== Кэширование запросов ==== |
<code php> | <code php> | ||
Строка 1193: | Строка 1216: | ||
}); | }); | ||
</ | </ | ||
- | ===== Статьи ===== | + | |
+ | ===== Локализация - i18N/intl ===== | ||
+ | |||
+ | apt=get install php5-intl | ||
+ | |||
+ | ==== Перевод (локализация проекта) ==== | ||
+ | |||
+ | * https:// | ||
+ | |||
+ | ===== PHPUnit ===== | ||
+ | |||
+ | добавить в конфигуратор композера composer.json | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | * php composer.phar update | ||
+ | * php vendor/ | ||
+ | |||
+ | ====== Статьи | ||
* https:// | * https:// | ||
* https:// | * https:// | ||
+ | * http:// | ||
- | + | ====== Описание | |
- | ===== Описание ===== | + | |
* https:// | * https:// | ||
* http:// | * http:// | ||
* http:// | * http:// | ||
+ |