Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/antonyz89/yii2-templates
Minor changes in model/crud templates for better experience and development
https://github.com/antonyz89/yii2-templates
Last synced: about 1 month ago
JSON representation
Minor changes in model/crud templates for better experience and development
- Host: GitHub
- URL: https://github.com/antonyz89/yii2-templates
- Owner: AntonyZ89
- Created: 2020-02-10T13:52:40.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-13T00:39:30.000Z (about 2 years ago)
- Last Synced: 2024-11-13T14:52:48.170Z (about 2 months ago)
- Language: PHP
- Homepage:
- Size: 111 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
yii2-templates
============Installation
------------The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require --prefer-dist antonyz89/yii2-templates dev-master
```or add
```
"antonyz89/yii2-templates": "dev-master"
```to the require section of your `composer.json` file.
Usage
-----
**environments/dev/common/config/main**and run ``php init`` again
```php
if (!YII_ENV_TEST) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['bootstrap'] = ['gii'];
$config['modules']['debug'] = 'yii\debug\Module';$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'generators' => [
'model' => [
'class' => 'antonyz89\templates\model\Generator',
'templates' => [
'default' => '@antonyz89/templates/model/default', // add default template
]
],
'crud' => [
'class' => 'antonyz89\templates\crud\Generator',
'templates' => [
'admin-lte' => '@antonyz89/templates/crud/admin-lte', // add admin-lte template
'material-lite' => '@antonyz89/templates/crud/material-lite', // add material-lite template
'material-bootstrap' => '@antonyz89/templates/crud/material-bootstrap', // add material-bootstrap template
'default' => '@antonyz89/templates/crud/default', // add default template
]
]
],
];
}
```Easy Pjax with `_search.php`
------**Kartik GridView ONLY**
CRUD generated by Gii with any template already do it, just add `YiiTemplateAsset` to complete
**Usage:**
1 - Just add `YiiTemplateAsset` on `YOUR_MODULE/assets/AppAsset`
```php
use antonyz89\templates\assets\YiiTemplatesAsset;class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [];
public $js = [];
public $depends = [
YiiTemplatesAsset::class // ADD
];
}
```2 - Now, just enable `pjax` on GridView
```php
GridView::widget([
'dataProvider' => $dataProvider,
'pjax' => true, // here
'columns' => [
'id',
'name',
[
'class' => 'kartik\grid\ActionColumn',
'width' => '150px',
'buttonOptions' => [
'class' => 'btn btn-sm btn-default'
],
'updateOptions' => [
'class' => 'btn btn-sm btn-primary'
],
'deleteOptions' => [
'class' => 'btn btn-sm btn-danger'
]
]
]
]);
```3 - Add `data-ajax => true` on _search's form
```php
['index'],
'method' => 'get',
'options' => [
'data-pjax' => true // HERE
],
]); ?>
= $form->field($model, 'id') ?>
= $form->field($model, 'name') ?>
```
DONE!Just type on _search's fields and GridView will reload
## Pjax only from form's submit
To use Pjax only from form's submit, just add `'pjax-only-on-submit' => true` on **ActiveForm::begin** from `_search.php`
```php
['index'],
'method' => 'get',
'options' => [
'data-pjax' => true,
'pjax-only-on-submit' => true // HERE
],
]); ?>```
## ActiveQuery
### Alias
Use `@alias.` on query to replace it with `::tableName` or `alias`.
```php
// Query
User::find()->alias('example')->where(['@alias.name' => 'Antony'])->groupBy('@alias.age');
```
```SQL
# result
SELECT `user`.* FROM `user` as `example` WHERE `example`.`name` = 'Antony' GROUP BY `example`.`age`
```### Disable GROUP BY
set `$query->groupBy(false)` to disable any `GROUP BY` on query