Commit 3cd1786b by Sujith Kumar

before back up aqq

parents
# Git
.git
# Environment settings
.env
# Composers
vendor
# Runtime
backend/runtime
common/runtime
frontend/runtime
console/runtime
# Assets
backend/web/assets
frontend/web/assets
# Framework
# ---------
YII_DEBUG = true
YII_ENV = dev
IS_SERVER = false
# Application
# -----------
LINK_ASSETS=true
# Databases
# ---------
DB_DSN = mysql:host=127.0.0.1;port=3306;dbname=yii_proj#1
DB_USERNAME = root
DB_PASSWORD =
DB_TABLE_PREFIX =yiiproj1_
TEST_DB_DSN = mysql:host=127.0.0.1;port=3306;dbname=yii_proj#1
TEST_DB_USERNAME = root
TEST_DB_PASSWORD =
# Urls
# ----
FRONTEND_URL = http://proj1.yii
BACKEND_URL = http://admin.proj1.yii
STORAGE_URL = http://storage.proj1.yii
# Other
# -----
SMTP_HOST = mailcatcher
SMTP_PORT = 1025
FRONTEND_COOKIE_VALIDATION_KEY = <generated_key>
BACKEND_COOKIE_VALIDATION_KEY = <generated_key>
ADMIN_EMAIL = admin@yii2-starter-kit.dev
ROBOT_EMAIL = robot@yii2-starter-kit.dev
GITHUB_CLIENT_ID = 1eb7b5fc0c7ac2e5425396ab7418618cf8f70603
GITHUB_CLIENT_SECRET = your-client-secret
GLIDE_SIGN_KEY = <generated_key>
GLIDE_MAX_IMAGE_SIZE = 4000000
# Autodetect text files
* text=auto
# ...Unless the name matches the following overriding patterns
# Definitively text files
*.php text
*.css text
*.js text
*.txt text
*.md text
*.xml text
*.json text
*.bat text
*.sql text
*.xml text
*.yml text
# Ensure those won't be messed up with
*.png binary
*.jpg binary
*.gif binary
*.ttf binary
# Ignore all test and documentation for archive
/.dockerignore export-ignore
/.gitattributes export-ignore
/.env.docker.dist export-ignore
/.travis.yml export-ignore
/.codeception.yml export-ignore
/.docker-compose.yml export-ignore
/.Dockerfile export-ignore
/.vhost.conf.dist export-ignore
/tests export-ignore
/docs export-ignore
/docker export-ignore
# Env
/.env
# composer
/vendor
composer.phar
## remove in production!
composer.lock
# IDE
.idea
nbproject
.buildpath
.project
.settings
# windows thumbnail cache
Thumbs.db
# Mac DS_Store Files
.DS_Store
# phpunit
phpunit.phar
/phpunit.xml
# Vagrant
/.vagrant
# Tests
tests/codeception/*/_support/_generated/*
Vagrantfile
backend/controllers/CategoryController.php
backend/controllers/ProductController.php
backend/controllers/PurchaseController.php
backend/controllers/StoreController.php
backend/controllers/SuppliersController.php
backend/models/SearchProducts.php
backend/models/SearchStores.php
backend/models/categorySearch.php
backend/models/searchPurchases.php
backend/models/suppliersSearch.php
backend/views/category/
backend/views/product/_form.php
backend/views/product/_search.php
backend/views/product/create.php
backend/views/product/index.php
backend/views/product/update.php
backend/views/product/view.php
backend/views/purchase/
backend/views/site/purchaseintro.php
backend/views/store/
backend/views/suppliers/
common/migrations/db/m161223_062921_purchaseintro.php
common/models/Category.php
common/models/Products.php
common/models/Purchaseintro.php
common/models/Purchases.php
common/models/Stores.php
common/models/Suppliers.php
storage/.quarantine/
yii_proj_1.sql
language: php
php:
- 5.5
- 5.6
- 7.0
# - hhvm
# faster builds on new travis setup not using sudo
sudo: false
services:
- mysql
# cache vendor dirs
cache:
directories:
- $HOME/.composer/cache
install:
- travis_retry phpenv config-rm xdebug.ini
- travis_retry composer self-update && composer --version
- travis_retry composer global require "fxp/composer-asset-plugin:~1.1.0" "codeception/codeception:^2.0" "codeception/specify" "codeception/verify"
- travis_retry composer install --dev --prefer-source --no-interaction
# setup application:
- |
cp .env.dist .env
sed -i s/yii2-starter-kit\.dev/localhost:8080/ .env
- |
cd tests/codeception/backend && codecept build
cd ../common && codecept build
cd ../console && codecept build
cd ../frontend && codecept build
cd ../../../
before_script:
- mysql -e 'CREATE DATABASE `yii2-starter-kit`;';
- php tests/codeception/bin/yii app/setup --interactive=0
script:
- |
php -S localhost:8080 > /dev/null 2>&1 &
cd tests
./../vendor/bin/codecept run --debug
\ No newline at end of file
Yii Starter Kit Change Log
==========================
dev-master
----------
- Enh #434: Added ability to control assets linking with env variable
- Fixed #428: Update for article categories didn't work on Yii 2.0.8
2.2.1
-----
- Fixed #407: Vagrant provisioning problems
- Fixed #400: Application initialization bug
- Added some sanitizing in ContactForm (#339)
- env() helper function added
- trntv/yii2-glide and trntv/yii2-command-bus versions updated
- Testing improvements
- PHP7 is now default for Vagrant
- Models are reformatted consistently as per conventions. #365
- Spanish translations was updated
- Fixed #392: The destinator of the mail was missing
- Maintenance mode works equally on all environments (#348)
2.2.0
-----
- Dockerfile based on PHP7
- Travis CI integration
2.1.3
-----
- Ads placing example
- DbText widget changes
- Fixed #368: User form fixes
- Fixed #369: missing field from user table in application tests
2.1.2
-----
- Fixed: Invalid user status validation
- Fixed #363: Remove references to password_reset_token
2.1.1
-----
- Mailcathcer support
- Optional user email activation
2.1.0
-----
- Enh #354: Command Bus implemented with yii2-command-bus extension
- Enh #321: editOwnModel permission
- Fixed #326
- API Fixes
- Fixed: password_confirm not validated
- Enh: Shortcuts file added
- Enh: Assets compression support
- Enh #192: Docker support
- Enh #223: Migrations for RBAC
- Enh #189: Added command bus
- Changed application setup proccess
- Enh #184: Preserve article attachments file name
- Enh #176: Added ability to set custom view for static pages and articles
- Enh #160: LocaleBehavior::enablePreferredLanguage
- fixes and improvements
2.0.0
-----
- Enh: Added Spanish locale
- Enh: Frontend Account and Profile actions merged into one
- Enh #146: Added MultiModel for handling multiple models at once
- Enh #145: Added Application settings + FormModel and FormWidget for keyStorage component
- Fixed: KeyStorage::set()
- Enh #147: implemented KeyStorage::has() and KeyStorage::hasAll()
- Enh: EnumColumn now loads enum as filter items
- Enh #37: REST API module example
- Enh #119: Removed default roles
- Enh #128: Articles are available via slugs
- Added Vagrant support
- testing framework configuration
- Imperavi redactor plugins enabled
- Upload Kit updated to 1.0
- AdminLTE updated to 2.0 branch
- PSR2 formatting
- ... fixes and many small changes ...
1.5.1
-----
- fixes
1.5.0
-----
- Enh: ``$cachingDuration`` parameter was added to ``common\components\keyStorage\KeyStorage::get``
- Fix: contact form fix
- Enh: "robot" email now ca be set in .env
- Enh #72: Maintenance mode
- Enh: #79 chosen locale is stored in cookies
- Enh: #84 Article Attachments
- Chg: application structure
- Chg #59: dotenv support
- Enh #61: Backend Cache Controller
- Enh: autocomplete now supports urlManagerFrontend and urlManagerBackend
- Enh #55: `components\grid\EnumColumn` for GridView
- Chng #52: Bower requirements was moved to composer
- Fix: Many `frontend/modules/user` fixes
- Fix: Autocompletion support
- Enh: FileCache now uses same path for all applications
- Enh: common\components\behaviors\CacheInvalidateBehavior
- ... Fixes ...
- Added ability to configure timezone and name of vagrant box
1.4.1
-----
- Cng #34: `Environment` class to configure application environment
- Chg: message-migrate has moved to console/controllers/ExtendedMessageController - `yii message/migrate @common/config/messages/php.php @common/config/messages/db.php`
- Eng #30: Tool to change code source language - `yii message/replace-source-language @path language-LOCALE`
1.4.0
-----
- Enh: backend user view page enhancement
- Enh #29: delete button on log record page
- Enh #28: init tool + local config files
- Fix #25: backend user update
- Chg: added utf-8 charset to nginx.conf
- Enh: Added filters for `log` and `file-storage` grids
- Enh: Backend now use `yii\bootstrap\ActiveForm` instead of `yii\widgets\ActiveForm`
- Enh: added `getFullName` for `UserProfile` and `getPublicIdentity` for `User`
- Fix: added some settings to prevent postfix `fatal: usage: sendmail [options]` error
- Enh: Gii Module has separate configs for backend and frontend
- Enh: Added gii templates for backend
- Enh: Time information on "system information" screen
- Fix #12: Locale bug
- Enh: I18N validation rules
- Enh: User backend controller don't available for `manager`
- Enh #11: OAuth authorization
- Fix #13: Article showing fix
- Enh: Xhprof debug panel
- ... many small enhancements and bugfixes ...
1.3.0
-----
- Enh: message configs for db, php and po formats
- Enh: `MessageController` migrate action
- Enh: I18N CRUD module
- Enh: `common\components\action\SetLocale`
- Enh: backendUrlManager, frontendUrlManager, bootstrap application
... enhancements, bugfixes
\ No newline at end of file
The Yii framework is free software. It is released under the terms of
the following BSD License.
Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Yii Software LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
#Proj#1
##Virtual host configuration
```
#proj#1 START
<VirtualHost *:80>
DocumentRoot "E:\php\yii\proj#1\backend\web"
ServerName admin.proj1.yii
<Directory "E:\php\yii\proj#1\backend\web">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "E:\php\yii\proj#1\storage\web"
ServerName storage.proj1.yii
<Directory "E:\php\yii\proj#1\storage\web">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "E:\php\yii\proj#1\frontend\web"
ServerName proj1.yii
<Directory "E:\php\yii\proj#1\frontend\web">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</Virtualhost>
#proj#1 END
```
##host file configuration
```
#proj#1
127.0.0.1 proj1.yii admin.proj1.yii storage.proj1.yii vendorpanel.proj1.yii
```
##Commands
<?php
/**
* Yii bootstrap file.
* Used for enhanced IDE code autocompletion.
* Note: To avoid "Multiple Implementations" PHPStorm warning and make autocomplete faster
* exclude or "Mark as Plain Text" vendor/yiisoft/yii2/Yii.php file
*/
class Yii extends \yii\BaseYii
{
/**
* @var BaseApplication|WebApplication|ConsoleApplication the application instance
*/
public static $app;
}
/**
* Class BaseApplication
* Used for properties that are identical for both WebApplication and ConsoleApplication
*
* @property trntv\filekit\Storage $fileStorage
* @property common\components\keyStorage\KeyStorage $keyStorage
* @property yii\web\UrlManager $urlManagerFrontend UrlManager for frontend application.
* @property yii\web\UrlManager $urlManagerBackend UrlManager for backend application.
* @property yii\web\UrlManager $urlManagerStorage UrlManager for storage application.
* @property trntv\glide\components\Glide $glide
* @property trntv\bus\CommandBus $commandBus
*/
abstract class BaseApplication extends yii\base\Application
{
}
/**
* Class WebApplication
* Include only Web application related components here
*
* @property User $user User component.
*/
class WebApplication extends yii\web\Application
{
}
/**
* Class ConsoleApplication
* Include only Console application related components here
*/
class ConsoleApplication extends yii\console\Application
{
}
/**
* User component
* Include only Web application related components here
*
* @property \common\models\User $identity User model.
* @method \common\models\User getIdentity() returns User model.
*/
class User extends \yii\web\User
{
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: zein
* Date: 7/3/14
* Time: 3:14 PM
*/
namespace backend\assets;
use yii\web\AssetBundle;
class BackendAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/style.css'
];
public $js = [
'js/app.js',
'js/main.js'
];
public $depends = [
'yii\web\YiiAsset',
'common\assets\AdminLte',
'common\assets\Html5shiv'
];
}
<?php
return [
'class'=>'yii\web\UrlManager',
'enablePrettyUrl'=>true,
'showScriptName'=>false,
'rules'=>[
// url rules
]
];
<?php
return [
'id' => 'backend',
'basePath' => dirname(__DIR__),
'components' => [
'urlManager' => require(__DIR__.'/_urlManager.php'),
'frontendCache' => require(Yii::getAlias('@frontend/config/_cache.php'))
],
];
<?php
/**
* @author Eugene Terentev <eugene@terentev.net>
*/
<?php
$config = [
'homeUrl'=>Yii::getAlias('@backendUrl'),
'controllerNamespace' => 'backend\controllers',
'defaultRoute'=>'store/index',
'controllerMap'=>[
'file-manager-elfinder' => [
'class' => 'mihaildev\elfinder\Controller',
'access' => ['manager'],
'disabledCommands' => ['netmount'],
'roots' => [
[
'baseUrl' => '@storageUrl',
'basePath' => '@storage',
'path' => '/',
'access' => ['read' => 'manager', 'write' => 'manager']
]
]
]
],
'components'=>[
'errorHandler' => [
'errorAction' => 'site/error',
],
'request' => [
'cookieValidationKey' => env('BACKEND_COOKIE_VALIDATION_KEY')
],
'user' => [
'class'=>'yii\web\User',
'identityClass' => 'common\models\User',
'loginUrl'=>['sign-in/login'],
'enableAutoLogin' => true,
'as afterLogin' => 'common\behaviors\LoginTimestampBehavior'
],
'jwplayer' => [
'class' => 'wadeshuler\jwplayer\JWConfig',
'key' => '/lq0VD8Briz9rSMS2ftRaI2foxKQw53JgF4EYg==', // <-- Your Key Here!!
'playerOptions' => [
'autostart' => true,
'sharing' => [
'sites' => ['facebook', 'twitter'],
],
],
]
],
'modules'=>[
'i18n' => [
'class' => 'backend\modules\i18n\Module',
'defaultRoute'=>'i18n-message/index'
],
'gridview' => [
'class' => '\kartik\grid\Module',
// enter optional module parameters below - only if you need to
// use your own export download action or custom translation
// message source
// 'downloadAction' => 'gridview/export/download',
// 'i18n' => []
// 'dataProvider'=>'\yii\data\BaseDataProvider',
],
],
'as globalAccess'=>[
'class'=>'\common\behaviors\GlobalAccessBehavior',
'rules'=>[
[
'controllers'=>['sign-in'],
'allow' => true,
'roles' => ['?'],
'actions'=>['login']
],
[
'controllers'=>['sign-in'],
'allow' => true,
'roles' => ['@'],
'actions'=>['logout']
],
[
'controllers'=>['site'],
'allow' => true,
'roles' => ['?', '@'],
'actions'=>['error']
],
[
'controllers'=>['debug/default'],
'allow' => true,
'roles' => ['?'],
],
[
'controllers'=>['user'],
'allow' => true,
'roles' => ['administrator'],
],
[
'controllers'=>['user'],
'allow' => false,
],
[
'allow' => true,
'roles' => ['manager'],
]
]
]
];
if (YII_ENV_DEV) {
$config['modules']['gii'] = [
'class'=>'yii\gii\Module',
'generators' => [
'crud' => [
'class'=>'yii\gii\generators\crud\Generator',
'templates'=>[
'yii2-starter-kit' => Yii::getAlias('@backend/views/_gii/templates')
],
'template' => 'yii2-starter-kit',
'messageCategory' => 'backend'
]
]
];
}
return $config;
<?php
namespace backend\controllers;
use Yii;
use common\models\ArticleCategory;
use backend\models\search\ArticleCategorySearch;
use yii\helpers\ArrayHelper;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* ArticleCategoryController implements the CRUD actions for ArticleCategory model.
*/
class ArticleCategoryController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all ArticleCategory models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new ArticleCategorySearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single ArticleCategory model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new ArticleCategory model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new ArticleCategory();
$categories = ArticleCategory::find()->noParents()->all();
$categories = ArrayHelper::map($categories, 'id', 'title');
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
'categories' => $categories,
]);
}
}
/**
* Updates an existing ArticleCategory model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$categories = ArticleCategory::find()->noParents()->andWhere(['not', ['id' => $id]])->all();
$categories = ArrayHelper::map($categories, 'id', 'title');
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('update', [
'model' => $model,
'categories' => $categories,
]);
}
}
/**
* Deletes an existing ArticleCategory model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the ArticleCategory model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return ArticleCategory the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = ArticleCategory::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
namespace backend\controllers;
use Yii;
use common\models\Article;
use backend\models\search\ArticleSearch;
use \common\models\ArticleCategory;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* ArticleController implements the CRUD actions for Article model.
*/
class ArticleController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post']
]
]
];
}
/**
* Lists all Article models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new ArticleSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->sort = [
'defaultOrder'=>['published_at'=>SORT_DESC]
];
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider
]);
}
/**
* Creates a new Article model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Article();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
'categories' => ArticleCategory::find()->active()->all(),
]);
}
}
/**
* Updates an existing Article model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('update', [
'model' => $model,
'categories' => ArticleCategory::find()->active()->all(),
]);
}
}
/**
* Deletes an existing Article model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Article model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Article the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Article::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
/**
* Eugine Terentev <eugine@terentev.net>
*/
namespace backend\controllers;
use Yii;
use yii\caching\Cache;
use yii\caching\TagDependency;
use yii\data\ArrayDataProvider;
use yii\filters\VerbFilter;
use yii\web\Controller;
use yii\web\HttpException;
/**
* Class CacheController
* @package backend\controllers
*/
class CacheController extends Controller
{
/**
* @return string
*/
public function actionIndex()
{
$dataProvider = new ArrayDataProvider(['allModels'=>$this->findCaches()]);
return $this->render('index', ['dataProvider'=>$dataProvider]);
}
/**
* @param $id
* @return \yii\web\Response
* @throws HttpException
*/
public function actionFlushCache($id)
{
if ($this->getCache($id)->flush()) {
Yii::$app->session->setFlash('alert', [
'body'=>\Yii::t('backend', 'Cache has been successfully flushed'),
'options'=>['class'=>'alert-success']
]);
};
return $this->redirect(['index']);
}
/**
* @param $id
* @param $key
* @return \yii\web\Response
* @throws HttpException
*/
public function actionFlushCacheKey($id, $key)
{
if ($this->getCache($id)->delete($key)) {
Yii::$app->session->setFlash('alert', [
'body'=>\Yii::t('backend', 'Cache entry has been successfully deleted'),
'options'=>['class'=>'alert-success']
]);
};
return $this->redirect(['index']);
}
/**
* @param $id
* @param $tag
* @return \yii\web\Response
* @throws HttpException
*/
public function actionFlushCacheTag($id, $tag)
{
TagDependency::invalidate($this->getCache($id), $tag);
Yii::$app->session->setFlash('alert', [
'body'=>\Yii::t('backend', 'TagDependency was invalidated'),
'options'=>['class'=>'alert-success']
]);
return $this->redirect(['index']);
}
/**
* @param $id
* @return \yii\caching\Cache|null
* @throws HttpException
* @throws \yii\base\InvalidConfigException
*/
protected function getCache($id)
{
if (!in_array($id, array_keys($this->findCaches()))) {
throw new HttpException(400, 'Given cache name is not a name of cache component');
}
return Yii::$app->get($id);
}
/**
* Returns array of caches in the system, keys are cache components names, values are class names.
* @param array $cachesNames caches to be found
* @return array
*/
private function findCaches(array $cachesNames = [])
{
$caches = [];
$components = Yii::$app->getComponents();
$findAll = ($cachesNames == []);
foreach ($components as $name => $component) {
if (!$findAll && !in_array($name, $cachesNames)) {
continue;
}
if ($component instanceof Cache) {
$caches[$name] = ['name'=>$name, 'class'=>get_class($component)];
} elseif (is_array($component) && isset($component['class']) && $this->isCacheClass($component['class'])) {
$caches[$name] = ['name'=>$name, 'class'=>$component['class']];
} elseif (is_string($component) && $this->isCacheClass($component)) {
$caches[$name] = ['name'=>$name, 'class'=>$component];
}
}
return $caches;
}
/**
* Checks if given class is a Cache class.
* @param string $className class name.
* @return boolean
*/
private function isCacheClass($className)
{
return is_subclass_of($className, Cache::className());
}
}
<?php
namespace backend\controllers;
class FileManagerController extends \yii\web\Controller
{
public function actionIndex()
{
return $this->render('index');
}
}
<?php
namespace backend\controllers;
use Yii;
use common\models\FileStorageItem;
use backend\models\search\FileStorageItemSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* FileStorageController implements the CRUD actions for FileStorageItem model.
*/
class FileStorageController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
'upload-delete' => ['delete']
]
]
];
}
public function actions()
{
return [
'upload' => [
'class' => 'trntv\filekit\actions\UploadAction',
'deleteRoute' => 'upload-delete'
],
'upload-delete' => [
'class' => 'trntv\filekit\actions\DeleteAction'
],
'upload-imperavi' => [
'class' => 'trntv\filekit\actions\UploadAction',
'fileparam' => 'file',
'responseUrlParam'=> 'filelink',
'multiple' => false,
'disableCsrf' => true
]
];
}
/**
* Lists all FileStorageItem models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new FileStorageItemSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->sort = [
'defaultOrder'=>['created_at'=>SORT_DESC]
];
$components = \yii\helpers\ArrayHelper::map(
FileStorageItem::find()->select('component')->distinct()->all(),
'component',
'component'
);
$totalSize = FileStorageItem::find()->sum('size') ?: 0;
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'components' => $components,
'totalSize' => $totalSize
]);
}
/**
* Displays a single FileStorageItem model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id)
]);
}
/**
* Deletes an existing FileStorageItem model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the FileStorageItem model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return FileStorageItem the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = FileStorageItem::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
namespace backend\controllers;
use Yii;
use common\models\KeyStorageItem;
use backend\models\search\KeyStorageItemSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* KeyStorageController implements the CRUD actions for KeyStorageItem model.
*/
class KeyStorageController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all KeyStorageItem models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new KeyStorageItemSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->sort = [
'defaultOrder'=>['key'=>SORT_DESC]
];
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Creates a new KeyStorageItem model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new KeyStorageItem();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing KeyStorageItem model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing KeyStorageItem model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the KeyStorageItem model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return KeyStorageItem the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = KeyStorageItem::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
namespace backend\controllers;
use Yii;
use backend\models\SystemLog;
use backend\models\search\SystemLogSearch;
use yii\helpers\VarDumper;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* LogController implements the CRUD actions for SystemLog model.
*/
class LogController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
'clear' => ['post'],
],
],
];
}
/**
* Lists all SystemLog models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new SystemLogSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
if (strcasecmp(Yii::$app->request->method, 'delete') == 0) {
SystemLog::deleteAll($dataProvider->query->where);
return $this->refresh();
}
$dataProvider->sort = [
'defaultOrder'=>['log_time'=>SORT_DESC]
];
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single SystemLog model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Deletes an existing SystemLog model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the SystemLog model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return SystemLog the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = SystemLog::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
namespace backend\controllers;
use Yii;
use common\models\Page;
use backend\models\search\PageSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* PageController implements the CRUD actions for Page model.
*/
class PageController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all Page models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new PageSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Creates a new Page model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Page();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing Page model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing Page model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Page model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Page the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Page::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
/**
* Created by PhpStorm.
* User: zein
* Date: 8/2/14
* Time: 11:20 AM
*/
namespace backend\controllers;
use backend\models\LoginForm;
use backend\models\AccountForm;
use Intervention\Image\ImageManagerStatic;
use trntv\filekit\actions\DeleteAction;
use trntv\filekit\actions\UploadAction;
use Yii;
use yii\filters\VerbFilter;
use yii\imagine\Image;
use yii\web\Controller;
class SignInController extends Controller
{
public $defaultAction = 'login';
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post']
]
]
];
}
public function actions()
{
return [
'avatar-upload' => [
'class' => UploadAction::className(),
'deleteRoute' => 'avatar-delete',
'on afterSave' => function ($event) {
/* @var $file \League\Flysystem\File */
$file = $event->file;
$img = ImageManagerStatic::make($file->read())->fit(215, 215);
$file->put($img->encode());
}
],
'avatar-delete' => [
'class' => DeleteAction::className()
]
];
}
public function actionLogin()
{
$this->layout = 'base';
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
return $this->render('login', [
'model' => $model
]);
}
}
public function actionLogout()
{
Yii::$app->user->logout();
return $this->goHome();
}
public function actionProfile()
{
$model = Yii::$app->user->identity->userProfile;
if ($model->load($_POST) && $model->save()) {
Yii::$app->session->setFlash('alert', [
'options'=>['class'=>'alert-success'],
'body'=>Yii::t('backend', 'Your profile has been successfully saved', [], $model->locale)
]);
return $this->refresh();
}
return $this->render('profile', ['model'=>$model]);
}
public function actionAccount()
{
$user = Yii::$app->user->identity;
$model = new AccountForm();
$model->username = $user->username;
$model->email = $user->email;
if ($model->load($_POST) && $model->validate()) {
$user->username = $model->username;
$user->email = $model->email;
if ($model->password) {
$user->setPassword($model->password);
}
$user->save();
Yii::$app->session->setFlash('alert', [
'options'=>['class'=>'alert-success'],
'body'=>Yii::t('backend', 'Your account has been successfully saved')
]);
return $this->refresh();
}
return $this->render('account', ['model'=>$model]);
}
}
<?php
namespace backend\controllers;
use Yii;
/**
* Site controller
*/
class SiteController extends \yii\web\Controller
{
/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
]
];
}
public function beforeAction($action)
{
$this->layout = Yii::$app->user->isGuest || !Yii::$app->user->can('loginToBackend') ? 'base' : 'common';
return parent::beforeAction($action);
}
public function actionSettings()
{
$model = new FormModel([
'keys' => [
'frontend.maintenance' => [
'label' => Yii::t('backend', 'Frontend maintenance mode'),
'type' => FormModel::TYPE_DROPDOWN,
'items' => [
'disabled' => Yii::t('backend', 'Disabled'),
'enabled' => Yii::t('backend', 'Enabled')
]
],
'backend.theme-skin' => [
'label' => Yii::t('backend', 'Backend theme'),
'type' => FormModel::TYPE_DROPDOWN,
'items' => [
'skin-black' => 'skin-black',
'skin-blue' => 'skin-blue',
'skin-green' => 'skin-green',
'skin-purple' => 'skin-purple',
'skin-red' => 'skin-red',
'skin-yellow' => 'skin-yellow'
]
],
'backend.layout-fixed' => [
'label' => Yii::t('backend', 'Fixed backend layout'),
'type' => FormModel::TYPE_CHECKBOX
],
'backend.layout-boxed' => [
'label' => Yii::t('backend', 'Boxed backend layout'),
'type' => FormModel::TYPE_CHECKBOX
],
'backend.layout-collapsed-sidebar' => [
'label' => Yii::t('backend', 'Backend sidebar collapsed'),
'type' => FormModel::TYPE_CHECKBOX
]
]
]);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash('alert', [
'body' => Yii::t('backend', 'Settings was successfully saved'),
'options' => ['class' => 'alert alert-success']
]);
return $this->refresh();
}
return $this->render('settings', ['model' => $model]);
}
}
<?php
/**
* Author: Eugine Terentev <eugine@terentev.net>
*/
namespace backend\controllers;
use probe\Factory;
use yii\helpers\Html;
use yii\web\Controller;
use yii\web\Response;
use Yii;
class SystemInformationController extends Controller
{
public $layout = 'common';
public function actionIndex()
{
$provider = Factory::create();
if ($provider) {
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
if ($key = Yii::$app->request->get('data')) {
switch($key){
case 'cpu_usage':
return$provider->getCpuUsage();
break;
case 'memory_usage':
return ($provider->getTotalMem() - $provider->getFreeMem()) / $provider->getTotalMem();
break;
}
}
} else {
return $this->render('index', ['provider' => $provider]);
}
} else {
return $this->render('fail');
}
}
}
<?php
namespace backend\controllers;
use Yii;
use backend\models\search\TimelineEventSearch;
use yii\web\Controller;
/**
* Application timeline controller
*/
class TimelineEventController extends Controller
{
public $layout = 'common';
/**
* Lists all TimelineEvent models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new TimelineEventSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->sort = [
'defaultOrder'=>['created_at'=>SORT_DESC]
];
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
}
<?php
namespace backend\controllers;
use Yii;
use common\models\User;
use backend\models\UserForm;
use backend\models\search\UserSearch;
use yii\helpers\ArrayHelper;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* UserController implements the CRUD actions for User model.
*/
class UserController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all User models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new UserSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single User model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new UserForm();
$model->setScenario('create');
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
}
return $this->render('create', [
'model' => $model,
'roles' => ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'name')
]);
}
/**
* Updates an existing User model.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = new UserForm();
$model->setModel($this->findModel($id));
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
}
return $this->render('update', [
'model' => $model,
'roles' => ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'name')
]);
}
/**
* Deletes an existing User model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
Yii::$app->authManager->revokeAll($id);
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return User the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = User::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
namespace backend\controllers;
use backend\models\search\WidgetCarouselItemSearch;
use Yii;
use common\models\WidgetCarousel;
use common\models\WidgetCarouselItem;
use backend\models\search\WidgetCarouselSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\Response;
use yii\web\UploadedFile;
/**
* WidgetCarouselController implements the CRUD actions for WidgetCarousel model.
*/
class WidgetCarouselController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post']
],
],
];
}
/**
* Lists all WidgetCarousel models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new WidgetCarouselSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Creates a new WidgetCarousel model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new WidgetCarousel();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['update', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing WidgetCarousel model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$searchModel = new WidgetCarouselItemSearch();
$carouselItemsProvider = $searchModel->search([]);
$carouselItemsProvider->query->andWhere(['carousel_id'=>$model->id]);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('update', [
'model' => $model,
'carouselItemsProvider'=>$carouselItemsProvider
]);
}
}
/**
* Deletes an existing WidgetCarousel model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the WidgetCarousel model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return WidgetCarousel the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = WidgetCarousel::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
namespace backend\controllers;
use common\models\WidgetCarousel;
use Yii;
use common\models\WidgetCarouselItem;
use backend\models\search\WidgetCarouselItemSearch;
use yii\web\Controller;
use yii\web\HttpException;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* WidgetCarouselItemController implements the CRUD actions for WidgetCarouselItem model.
*/
class WidgetCarouselItemController extends Controller
{
public function getViewPath()
{
return $this->module->getViewPath() . DIRECTORY_SEPARATOR . 'widget-carousel/item';
}
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Creates a new WidgetCarouselItem model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate($carousel_id)
{
$model = new WidgetCarouselItem();
$carousel = WidgetCarousel::findOne($carousel_id);
if (!$carousel) {
throw new HttpException(400);
}
$model->carousel_id = $carousel->id;
if ($model->load(Yii::$app->request->post())) {
if ($model->save()) {
Yii::$app->getSession()->setFlash('alert', ['options'=>['class'=>'alert-success'], 'body'=>Yii::t('backend', 'Carousel slide was successfully saved')]);
return $this->redirect(['/widget-carousel/update', 'id' => $model->carousel_id]);
}
}
return $this->render('create', [
'model' => $model,
'carousel' => $carousel,
]);
}
/**
* Updates an existing WidgetCarouselItem model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->getSession()->setFlash('alert', ['options'=>['class'=>'alert-success'], 'body'=>Yii::t('backend', 'Carousel slide was successfully saved')]);
return $this->redirect(['/widget-carousel/update', 'id' => $model->carousel_id]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing WidgetCarouselItem model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$model = $this->findModel($id);
if ($model->delete()) {
return $this->redirect(['/widget-carousel/update', 'id'=>$model->carousel_id]);
};
}
/**
* Finds the WidgetCarouselItem model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return WidgetCarouselItem the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = WidgetCarouselItem::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
namespace backend\controllers;
use Yii;
use common\models\WidgetMenu;
use backend\models\search\WidgetMenuSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* WidgetMenuController implements the CRUD actions for WidgetMenu model.
*/
class WidgetMenuController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all WidgetMenu models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new WidgetMenuSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Creates a new WidgetMenu model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new WidgetMenu();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing WidgetMenu model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing WidgetMenu model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the WidgetMenu model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return WidgetMenu the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = WidgetMenu::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
namespace backend\controllers;
use backend\models\search\WidgetTextSearch;
use Yii;
use common\models\WidgetText;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* WidgetTextController implements the CRUD actions for WidgetText model.
*/
class WidgetTextController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all WidgetText models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new WidgetTextSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Creates a new WidgetText model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new WidgetText();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing WidgetText model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing WidgetText model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the WidgetText model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return WidgetText the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = WidgetText::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
use yii\helpers\Html;
/* @var $this \yii\web\View view component instance */
/* @var $message \yii\mail\MessageInterface the message bing composed */
/* @var $content string main view render result */
?>
<?php $this->beginPage() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo Yii::$app->charset ?>" />
<title><?php echo Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<?php echo $content ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
<?php
/* @var $this \yii\web\View view component instance */
/* @var $message \yii\mail\MessageInterface the message bing composed */
/* @var $content string main view render result */
echo $content;
<?php
namespace backend\models;
use yii\base\Model;
use Yii;
/**
* Account form
*/
class AccountForm extends Model
{
public $username;
public $email;
public $password;
public $password_confirm;
/**
* @inheritdoc
*/
public function rules()
{
return [
['username', 'filter', 'filter' => 'trim'],
['username', 'required'],
['username', 'unique',
'targetClass'=>'\common\models\User',
'message' => Yii::t('backend', 'This username has already been taken.'),
'filter' => function ($query) {
$query->andWhere(['not', ['id' => Yii::$app->user->id]]);
}
],
['username', 'string', 'min' => 1, 'max' => 255],
['email', 'filter', 'filter' => 'trim'],
['email', 'required'],
['email', 'email'],
['email', 'unique',
'targetClass'=>'\common\models\User',
'message' => Yii::t('backend', 'This email has already been taken.'),
'filter' => function ($query) {
$query->andWhere(['not', ['id' => Yii::$app->user->getId()]]);
}
],
['password', 'string'],
[['password_confirm'], 'compare', 'compareAttribute' => 'password']
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'username' => Yii::t('backend', 'Username'),
'email' => Yii::t('backend', 'Email'),
'password' => Yii::t('backend', 'Password'),
'password_confirm' => Yii::t('backend', 'Password Confirm')
];
}
}
<?php
namespace backend\models;
use cheatsheet\Time;
use common\models\User;
use Yii;
use yii\base\Exception;
use yii\base\Model;
use yii\web\ForbiddenHttpException;
/**
* Login form
*/
class LoginForm extends Model
{
public $username;
public $password;
public $rememberMe = true;
private $user = false;
/**
* @inheritdoc
*/
public function rules()
{
return [
// username and password are both required
[['username', 'password'], 'required'],
// rememberMe must be a boolean value
['rememberMe', 'boolean'],
// password is validated by validatePassword()
['password', 'validatePassword'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'username' => Yii::t('backend', 'Username'),
'password' => Yii::t('backend', 'Password'),
'rememberMe' => Yii::t('backend', 'Remember Me')
];
}
/**
* Validates the password.
* This method serves as the inline validation for password.
*/
public function validatePassword()
{
if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
$this->addError('password', Yii::t('backend', 'Incorrect username or password.'));
}
}
}
/**
* Logs in a user using the provided username and password.
* @return bool whether the user is logged in successfully
* @throws ForbiddenHttpException
*/
public function login()
{
if (!$this->validate()) {
return false;
}
$duration = $this->rememberMe ? Time::SECONDS_IN_A_MONTH : 0;
if (Yii::$app->user->login($this->getUser(), $duration)) {
if (!Yii::$app->user->can('loginToBackend')) {
Yii::$app->user->logout();
throw new ForbiddenHttpException;
}
return true;
}
return false;
}
/**
* Finds user by [[username]]
*
* @return User|null
*/
public function getUser()
{
if ($this->user === false) {
$this->user = User::find()
->andWhere(['or', ['username'=>$this->username], ['email'=>$this->username]])
->one();
}
return $this->user;
}
}
<?php
namespace backend\models;
use backend\models\query\SystemLogQuery;
use Yii;
/**
* This is the model class for table "system_log".
*
* @property integer $id
* @property integer $level
* @property string $category
* @property integer $log_time
* @property string $prefix
* @property integer $message
*/
class SystemLog extends \yii\db\ActiveRecord
{
const CATEGORY_NOTIFICATION = 'notification';
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%system_log}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['level', 'log_time', 'message'], 'integer'],
[['log_time'], 'required'],
[['prefix'], 'string'],
[['category'], 'string', 'max' => 255]
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('backend', 'ID'),
'level' => Yii::t('backend', 'Level'),
'category' => Yii::t('backend', 'Category'),
'log_time' => Yii::t('backend', 'Log Time'),
'prefix' => Yii::t('backend', 'Prefix'),
'message' => Yii::t('backend', 'Message'),
];
}
}
<?php
namespace backend\models;
use common\models\User;
use yii\base\Exception;
use yii\base\Model;
use Yii;
use yii\helpers\ArrayHelper;
/**
* Create user form
*/
class UserForm extends Model
{
public $username;
public $email;
public $password;
public $status;
public $roles;
private $model;
/**
* @inheritdoc
*/
public function rules()
{
return [
['username', 'filter', 'filter' => 'trim'],
['username', 'required'],
['username', 'unique', 'targetClass' => User::className(), 'filter' => function ($query) {
if (!$this->getModel()->isNewRecord) {
$query->andWhere(['not', ['id'=>$this->getModel()->id]]);
}
}],
['username', 'string', 'min' => 2, 'max' => 255],
['email', 'filter', 'filter' => 'trim'],
['email', 'required'],
['email', 'email'],
['email', 'unique', 'targetClass'=> User::className(), 'filter' => function ($query) {
if (!$this->getModel()->isNewRecord) {
$query->andWhere(['not', ['id'=>$this->getModel()->id]]);
}
}],
['password', 'required', 'on' => 'create'],
['password', 'string', 'min' => 6],
[['status'], 'integer'],
[['roles'], 'each',
'rule' => ['in', 'range' => ArrayHelper::getColumn(
Yii::$app->authManager->getRoles(),
'name'
)]
],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'username' => Yii::t('common', 'Username'),
'email' => Yii::t('common', 'Email'),
'status' => Yii::t('common', 'Status'),
'password' => Yii::t('common', 'Password'),
'roles' => Yii::t('common', 'Roles')
];
}
/**
* @param User $model
* @return mixed
*/
public function setModel($model)
{
$this->username = $model->username;
$this->email = $model->email;
$this->status = $model->status;
$this->model = $model;
$this->roles = ArrayHelper::getColumn(
Yii::$app->authManager->getRolesByUser($model->getId()),
'name'
);
return $this->model;
}
/**
* @return User
*/
public function getModel()
{
if (!$this->model) {
$this->model = new User();
}
return $this->model;
}
/**
* Signs user up.
* @return User|null the saved model or null if saving fails
* @throws Exception
*/
public function save()
{
if ($this->validate()) {
$model = $this->getModel();
$isNewRecord = $model->getIsNewRecord();
$model->username = $this->username;
$model->email = $this->email;
$model->status = $this->status;
if ($this->password) {
$model->setPassword($this->password);
}
if (!$model->save()) {
throw new Exception('Model not saved');
}
if ($isNewRecord) {
$model->afterSignup();
}
$auth = Yii::$app->authManager;
$auth->revokeAll($model->getId());
if ($this->roles && is_array($this->roles)) {
foreach ($this->roles as $role) {
$auth->assign($auth->getRole($role), $model->getId());
}
}
return !$model->hasErrors();
}
return null;
}
}
<?php
namespace backend\models\search;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\ArticleCategory;
/**
* ArticleCategorySearch represents the model behind the search form about `common\models\ArticleCategory`.
*/
class ArticleCategorySearch extends ArticleCategory
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'status'], 'integer'],
[['slug', 'title'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
* @return ActiveDataProvider
*/
public function search($params)
{
$query = ArticleCategory::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'status' => $this->status,
]);
$query->andFilterWhere(['like', 'slug', $this->slug])
->andFilterWhere(['like', 'title', $this->title]);
return $dataProvider;
}
}
<?php
namespace backend\models\search;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Article;
/**
* ArticleSearch represents the model behind the search form about `common\models\Article`.
*/
class ArticleSearch extends Article
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'category_id', 'created_by', 'updated_by', 'status', 'published_at', 'created_at', 'updated_at'], 'integer'],
[['slug', 'title', 'body'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Article::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'slug' => $this->slug,
'created_by' => $this->created_by,
'category_id' => $this->category_id,
'updated_by' => $this->updated_by,
'status' => $this->status,
'published_at' => $this->published_at,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'slug', $this->slug])
->andFilterWhere(['like', 'title', $this->title])
->andFilterWhere(['like', 'body', $this->body]);
return $dataProvider;
}
}
<?php
namespace backend\models\search;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\FileStorageItem;
/**
* FileStorageItemSearch represents the model behind the search form about `common\models\FileStorageItem`.
*/
class FileStorageItemSearch extends FileStorageItem
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'size', 'created_at'], 'integer'],
[['component', 'base_url', 'path', 'type', 'name', 'upload_ip'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = FileStorageItem::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'size' => $this->size,
'created_at' => $this->created_at,
]);
$query->andFilterWhere(['like', 'component', $this->component])
->andFilterWhere(['like', 'base_url', $this->base_url])
->andFilterWhere(['like', 'path', $this->path])
->andFilterWhere(['like', 'type', $this->type])
->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'upload_ip', $this->upload_ip]);
return $dataProvider;
}
}
<?php
namespace backend\models\search;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\KeyStorageItem;
/**
* KeyStorageItemSearch represents the model behind the search form about `common\models\KeyStorageItem`.
*/
class KeyStorageItemSearch extends KeyStorageItem
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['key', 'value'], 'string'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = KeyStorageItem::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'like', 'key', $this->key
]);
$query->andFilterWhere([
'like', 'value', $this->value
]);
return $dataProvider;
}
}
<?php
namespace backend\models\search;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Page;
/**
* PageSearch represents the model behind the search form about `common\models\Page`.
*/
class PageSearch extends Page
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'status'], 'integer'],
[['slug', 'title', 'body'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Page::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'status' => $this->status,
]);
$query->andFilterWhere(['like', 'slug', $this->slug])
->andFilterWhere(['like', 'title', $this->title])
->andFilterWhere(['like', 'body', $this->body]);
return $dataProvider;
}
}
<?php
namespace backend\models\search;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\SystemLog;
/**
* SystemLogSearch represents the model behind the search form about `backend\models\SystemLog`.
*/
class SystemLogSearch extends SystemLog
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'log_time', 'message'], 'integer'],
[['category', 'prefix', 'level'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
* @return ActiveDataProvider
*/
public function search($params)
{
$query = SystemLog::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'level' => $this->level,
'log_time' => $this->log_time,
'message' => $this->message,
]);
$query->andFilterWhere(['like', 'category', $this->category])
->andFilterWhere(['like', 'prefix', $this->prefix]);
return $dataProvider;
}
}
<?php
namespace backend\models\search;
use common\models\TimelineEvent;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
/**
* TimelineEventSearch represents the model behind the search form about `common\models\TimelineEvent`.
*/
class TimelineEventSearch extends TimelineEvent
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['application', 'category', 'event', 'created_at'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = TimelineEvent::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'created_at' => $this->created_at,
]);
$query->andFilterWhere(['like', 'application', $this->application]);
$query->andFilterWhere(['like', 'category', $this->category]);
$query->andFilterWhere(['like', 'event', $this->event]);
return $dataProvider;
}
}
<?php
namespace backend\models\search;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\User;
/**
* UserSearch represents the model behind the search form about `common\models\User`.
*/
class UserSearch extends User
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'status', 'created_at', 'updated_at', 'logged_at'], 'integer'],
[['username', 'auth_key', 'password_hash', 'email'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
* @return ActiveDataProvider
*/
public function search($params)
{
$query = User::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'status' => $this->status,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'logged_at' => $this->logged_at
]);
$query->andFilterWhere(['like', 'username', $this->username])
->andFilterWhere(['like', 'auth_key', $this->auth_key])
->andFilterWhere(['like', 'password_hash', $this->password_hash])
->andFilterWhere(['like', 'email', $this->email]);
return $dataProvider;
}
}
<?php
namespace backend\models\search;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\WidgetCarouselItem;
/**
* WidgetCarouselItemSearch represents the model behind the search form about `common\models\WidgetCarouselItem`.
*/
class WidgetCarouselItemSearch extends WidgetCarouselItem
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'carousel_id', 'status', 'order'], 'integer'],
[['path', 'url', 'caption'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
* @param array $params
* @return ActiveDataProvider
*/
public function search($params = null)
{
$query = WidgetCarouselItem::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'carousel_id' => $this->carousel_id,
'status' => $this->status,
'order' => $this->order,
]);
$query->andFilterWhere(['like', 'path', $this->path])
->andFilterWhere(['like', 'url', $this->url])
->andFilterWhere(['like', 'caption', $this->caption]);
return $dataProvider;
}
}
<?php
namespace backend\models\search;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\WidgetCarousel;
/**
* WidgetCarouselSearch represents the model behind the search form about `common\models\WidgetCarousel`.
*/
class WidgetCarouselSearch extends WidgetCarousel
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'status'], 'integer'],
[['key'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
* @return ActiveDataProvider
*/
public function search($params)
{
$query = WidgetCarousel::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'status' => $this->status,
]);
$query->andFilterWhere(['like', 'key', $this->key]);
return $dataProvider;
}
}
<?php
namespace backend\models\search;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\WidgetMenu;
/**
* WidgetMenuSearch represents the model behind the search form about `common\models\WidgetMenu`.
*/
class WidgetMenuSearch extends WidgetMenu
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'status'], 'integer'],
[['key', 'title', 'items'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
* @return ActiveDataProvider
*/
public function search($params)
{
$query = WidgetMenu::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'status' => $this->status,
]);
$query->andFilterWhere(['like', 'key', $this->key])
->andFilterWhere(['like', 'title', $this->title])
->andFilterWhere(['like', 'items', $this->items]);
return $dataProvider;
}
}
<?php
namespace backend\models\search;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\WidgetText;
class WidgetTextSearch extends WidgetText
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'status'], 'integer'],
[['key', 'title', 'body'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
* @return ActiveDataProvider
*/
public function search($params)
{
$query = WidgetText::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'status' => $this->status,
]);
$query->andFilterWhere(['like', 'key', $this->key])
->andFilterWhere(['like', 'title', $this->title])
->andFilterWhere(['like', 'body', $this->body]);
return $dataProvider;
}
}
<?php
namespace backend\modules\i18n;
class Module extends \yii\base\Module
{
public $controllerNamespace = 'backend\modules\i18n\controllers';
public function init()
{
parent::init();
}
/**
* @param \yii\i18n\MissingTranslationEvent $event
*/
public static function missingTranslation($event)
{
// do something with missing translation
}
}
<?php
namespace backend\modules\i18n\controllers;
use backend\modules\i18n\models\I18nSourceMessage;
use Yii;
use backend\modules\i18n\models\I18nMessage;
use backend\modules\i18n\models\search\I18nMessageSearch;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* I18nMessageController implements the CRUD actions for I18nMessage model.
*/
class I18nMessageController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all I18nMessage models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new I18nMessageSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
Url::remember(Yii::$app->request->getUrl(), 'i18n-messages-filter');
$languages = ArrayHelper::map(
I18nMessage::find()->select('language')->distinct()->all(),
'language',
'language'
);
$categories = ArrayHelper::map(
I18nSourceMessage::find()->select('category')->distinct()->all(),
'category',
'category'
);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'languages' => $languages,
'categories' => $categories
]);
}
/**
* Creates a new I18nMessage model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new I18nMessage();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing I18nMessage model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @param string $language
* @return mixed
*/
public function actionUpdate($id, $language)
{
$model = $this->findModel($id, $language);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(Url::previous('i18n-messages-filter') ?: ['index']);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing I18nMessage model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @param string $language
* @return mixed
*/
public function actionDelete($id, $language)
{
$this->findModel($id, $language)->delete();
return $this->redirect(['index']);
}
/**
* Finds the I18nMessage model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @param string $language
* @return I18nMessage the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id, $language)
{
if (($model = I18nMessage::findOne(['id' => $id, 'language' => $language])) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
namespace backend\modules\i18n\controllers;
use Yii;
use backend\modules\i18n\models\I18nSourceMessage;
use backend\modules\i18n\models\search\I18nSourceMessageSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* I18nSourceMessageController implements the CRUD actions for I18nSourceMessage model.
*/
class I18nSourceMessageController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all I18nSourceMessage models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new I18nSourceMessageSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single I18nSourceMessage model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new I18nSourceMessage model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new I18nSourceMessage();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing I18nSourceMessage model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing I18nSourceMessage model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the I18nSourceMessage model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return I18nSourceMessage the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = I18nSourceMessage::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
namespace backend\modules\i18n\models;
use Yii;
/**
* This is the model class for table "{{%i18n_message}}".
*
* @property integer $id
* @property string $language
* @property string $translation
* @property string $sourceMessage
* @property string $category
*
* @property I18nSourceMessage $sourceMessageModel
*/
class I18nMessage extends \yii\db\ActiveRecord
{
public $category;
public $sourceMessage;
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%i18n_message}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'language'], 'required'],
[['id'], 'exist', 'targetClass'=>I18nSourceMessage::className(), 'targetAttribute'=>'id'],
[['translation'], 'string'],
[['language'], 'string', 'max' => 16],
[['language'], 'unique', 'targetAttribute' => ['id', 'language']]
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('backend', 'ID'),
'language' => Yii::t('backend', 'Language'),
'translation' => Yii::t('backend', 'Translation'),
'sourceMessage' => Yii::t('backend', 'Source Message'),
'category' => Yii::t('backend', 'Category'),
];
}
public function afterFind()
{
$this->sourceMessage = $this->sourceMessageModel ? $this->sourceMessageModel->message : null;
$this->category = $this->sourceMessageModel ? $this->sourceMessageModel->category : null;
return parent::afterFind();
}
/**
* @return \yii\db\ActiveQuery
*/
public function getSourceMessageModel()
{
return $this->hasOne(I18nSourceMessage::className(), ['id' => 'id']);
}
}
<?php
namespace backend\modules\i18n\models;
use Yii;
/**
* This is the model class for table "{{%i18n_source_message}}".
*
* @property integer $id
* @property string $category
* @property string $message
*
* @property I18nMessage[] $i18nMessages
*/
class I18nSourceMessage extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%i18n_source_message}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['message'], 'string'],
[['category'], 'string', 'max' => 32]
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('backend', 'ID'),
'category' => Yii::t('backend', 'Category'),
'message' => Yii::t('backend', 'Message'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getI18nMessages()
{
return $this->hasMany(I18nMessage::className(), ['id' => 'id']);
}
}
<?php
namespace backend\modules\i18n\models\search;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\i18n\models\I18nMessage;
/**
* I18nMessageSearch represents the model behind the search form about `backend\modules\i18n\models\I18nMessage`.
*/
class I18nMessageSearch extends I18nMessage
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id'], 'integer'],
[['language', 'translation', 'sourceMessage', 'category'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = I18nMessage::find()->with('sourceMessageModel')->joinWith('sourceMessageModel');
$dataProvider = new ActiveDataProvider([
'query' => $query
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'{{%i18n_source_message}}.id' => $this->id
]);
$query->andFilterWhere(['like', '{{%i18n_message}}.language', $this->language])
->andFilterWhere(['like', '{{%i18n_message}}.translation', $this->translation])
->andFilterWhere(['like', '{{%i18n_source_message}}.message', $this->sourceMessage])
->andFilterWhere(['like', '{{%i18n_source_message}}.category', $this->category]);
return $dataProvider;
}
}
<?php
namespace backend\modules\i18n\models\search;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\i18n\models\I18nSourceMessage;
/**
* I18nSourceMessageSearch represents the model behind the search form about `backend\modules\i18n\models\I18nSourceMessage`.
*/
class I18nSourceMessageSearch extends I18nSourceMessage
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id'], 'integer'],
[['category', 'message'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = I18nSourceMessage::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere([
'{{%i18n_source_message}}.id' => $this->id,
]);
$query->andFilterWhere(['like', '{{%i18n_source_message}}.category', $this->category])
->andFilterWhere(['like', '{{%i18n_source_message}}.message', $this->message]);
return $dataProvider;
}
}
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\i18n\models\I18nMessage */
/* @var $form yii\bootstrap\ActiveForm */
?>
<div class="i18n-message-form">
<?php $form = ActiveForm::begin(); ?>
<?php echo $form->field($model, 'id')->textInput(['disabled'=>!$model->isNewRecord]) ?>
<?php if (!$model->isNewRecord): ?>
<?php echo $form->field($model, 'category')->textInput(['disabled'=>true]) ?>
<?php echo $form->field($model, 'sourceMessage')->textInput(['disabled'=>true]) ?>
<?php endif; ?>
<?php echo $form->field($model, 'language')->textInput(['maxlength' => 16]) ?>
<?php echo $form->field($model, 'translation')->textarea(['rows' => 6]) ?>
<div class="form-group">
<?php echo Html::submitButton($model->isNewRecord ? Yii::t('backend', 'Create') : Yii::t('backend', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\i18n\models\search\I18nMessageSearch */
/* @var $form yii\bootstrap\ActiveForm */
?>
<div class="i18n-message-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?php echo $form->field($model, 'id') ?>
<?php echo $form->field($model, 'language') ?>
<?php echo $form->field($model, 'translation') ?>
<div class="form-group">
<?php echo Html::submitButton(Yii::t('backend', 'Search'), ['class' => 'btn btn-primary']) ?>
<?php echo Html::resetButton(Yii::t('backend', 'Reset'), ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php
/* @var $this yii\web\View */
/* @var $model backend\modules\i18n\models\I18nMessage */
$this->title = Yii::t('backend', 'Create {modelClass}', [
'modelClass' => 'I18n Message',
]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'I18n Messages'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="i18n-message-create">
<?php echo $this->render('_form', [
'model' => $model
]) ?>
</div>
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\i18n\models\search\I18nMessageSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('backend', 'I18n Messages');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="i18n-message-index">
<?php //echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?php echo Html::a(Yii::t('backend', 'Create {modelClass}', [
'modelClass' => 'I18n Message',
]), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'options' => [
'class' => 'grid-view table-responsive'
],
'columns' => [
'id',
[
'attribute'=>'language',
'filter'=> $languages
],
[
'attribute'=>'category',
'filter'=> $categories
],
'sourceMessage',
'translation:ntext',
['class' => 'yii\grid\ActionColumn', 'template'=>'{update} {delete}'],
],
]); ?>
</div>
\ No newline at end of file
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model backend\modules\i18n\models\I18nMessage */
$this->title = Yii::t('backend', 'Update {modelClass}: ', [
'modelClass' => 'I18n Message',
]) . ' ' . $model->id;
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'I18n Messages'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id, 'language' => $model->language]];
$this->params['breadcrumbs'][] = Yii::t('backend', 'Update');
?>
<div class="i18n-message-update">
<?php echo $this->render('_form', [
'model' => $model,
]) ?>
</div>
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\i18n\models\I18nSourceMessage */
/* @var $form yii\bootstrap\ActiveForm */
?>
<div class="i18n-source-message-form">
<?php $form = ActiveForm::begin(); ?>
<?php echo $form->field($model, 'category')->textInput(['maxlength' => 32]) ?>
<?php echo $form->field($model, 'message')->textarea(['rows' => 6]) ?>
<div class="form-group">
<?php echo Html::submitButton($model->isNewRecord ? Yii::t('backend', 'Create') : Yii::t('backend', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\i18n\models\search\I18nSourceMessageSearch */
/* @var $form yii\bootstrap\ActiveForm */
?>
<div class="i18n-source-message-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?php echo $form->field($model, 'id') ?>
<?php echo $form->field($model, 'category') ?>
<?php echo $form->field($model, 'message') ?>
<div class="form-group">
<?php echo Html::submitButton(Yii::t('backend', 'Search'), ['class' => 'btn btn-primary']) ?>
<?php echo Html::resetButton(Yii::t('backend', 'Reset'), ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php
/* @var $this yii\web\View */
/* @var $model backend\modules\i18n\models\I18nSourceMessage */
$this->title = Yii::t('backend', 'Create {modelClass}', [
'modelClass' => 'I18n Source Message',
]);
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'I18n Source Messages'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="i18n-source-message-create">
<?php echo $this->render('_form', [
'model' => $model
]) ?>
</div>
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\i18n\models\search\I18nSourceMessageSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('backend', 'I18n Source Messages');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="i18n-source-message-index">
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?php echo Html::a(Yii::t('backend', 'Create {modelClass}', [
'modelClass' => 'I18n Source Message',
]), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'options' => [
'class' => 'grid-view table-responsive'
],
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'category',
'message:ntext',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model backend\modules\i18n\models\I18nSourceMessage */
$this->title = Yii::t('backend', 'Update {modelClass}: ', [
'modelClass' => 'I18n Source Message',
]) . ' ' . $model->id;
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'I18n Source Messages'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = Yii::t('backend', 'Update');
?>
<div class="i18n-source-message-update">
<?php echo $this->render('_form', [
'model' => $model,
]) ?>
</div>
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model backend\modules\i18n\models\I18nSourceMessage */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'I18n Source Messages'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="i18n-source-message-view">
<h1><?php echo Html::encode($this->title) ?></h1>
<p>
<?php echo Html::a(Yii::t('backend', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?php echo Html::a(Yii::t('backend', 'Delete'), ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => Yii::t('backend', 'Are you sure you want to delete this item?'),
'method' => 'post',
],
]) ?>
</p>
<?php echo DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'category',
'message:ntext',
],
]) ?>
</div>
*
!.gitignore
\ No newline at end of file
<?php
/**
* This is the template for generating a CRUD controller class file.
*/
use yii\db\ActiveRecordInterface;
use yii\helpers\StringHelper;
/* @var $this yii\web\View */
/* @var $generator yii\gii\generators\crud\Generator */
$controllerClass = StringHelper::basename($generator->controllerClass);
$modelClass = StringHelper::basename($generator->modelClass);
$searchModelClass = StringHelper::basename($generator->searchModelClass);
if ($modelClass === $searchModelClass) {
$searchModelAlias = $searchModelClass . 'Search';
}
/* @var $class ActiveRecordInterface */
$class = $generator->modelClass;
$pks = $class::primaryKey();
$urlParams = $generator->generateUrlParams();
$actionParams = $generator->generateActionParams();
$actionParamComments = $generator->generateActionParamComments();
echo "<?php\n";
?>
namespace <?php echo StringHelper::dirname(ltrim($generator->controllerClass, '\\')) ?>;
use Yii;
use <?php echo ltrim($generator->modelClass, '\\') ?>;
<?php if (!empty($generator->searchModelClass)): ?>
use <?php echo ltrim($generator->searchModelClass, '\\') . (isset($searchModelAlias) ? " as $searchModelAlias" : "") ?>;
<?php else: ?>
use yii\data\ActiveDataProvider;
<?php endif; ?>
use <?php echo ltrim($generator->baseControllerClass, '\\') ?>;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* <?php echo $controllerClass ?> implements the CRUD actions for <?php echo $modelClass ?> model.
*/
class <?php echo $controllerClass ?> extends <?php echo StringHelper::basename($generator->baseControllerClass) . "\n" ?>
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all <?php echo $modelClass ?> models.
* @return mixed
*/
public function actionIndex()
{
<?php if (!empty($generator->searchModelClass)): ?>
$searchModel = new <?php echo isset($searchModelAlias) ? $searchModelAlias : $searchModelClass ?>();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
<?php else: ?>
$dataProvider = new ActiveDataProvider([
'query' => <?php echo $modelClass ?>::find(),
]);
return $this->render('index', [
'dataProvider' => $dataProvider,
]);
<?php endif; ?>
}
/**
* Displays a single <?php echo $modelClass ?> model.
* <?php echo implode("\n * ", $actionParamComments) . "\n" ?>
* @return mixed
*/
public function actionView(<?php echo $actionParams ?>)
{
return $this->render('view', [
'model' => $this->findModel(<?php echo $actionParams ?>),
]);
}
/**
* Creates a new <?php echo $modelClass ?> model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new <?php echo $modelClass ?>();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', <?php echo $urlParams ?>]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing <?php echo $modelClass ?> model.
* If update is successful, the browser will be redirected to the 'view' page.
* <?php echo implode("\n * ", $actionParamComments) . "\n" ?>
* @return mixed
*/
public function actionUpdate(<?php echo $actionParams ?>)
{
$model = $this->findModel(<?php echo $actionParams ?>);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', <?php echo $urlParams ?>]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing <?php echo $modelClass ?> model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* <?php echo implode("\n * ", $actionParamComments) . "\n" ?>
* @return mixed
*/
public function actionDelete(<?php echo $actionParams ?>)
{
$this->findModel(<?php echo $actionParams ?>)->delete();
return $this->redirect(['index']);
}
/**
* Finds the <?php echo $modelClass ?> model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* <?php echo implode("\n * ", $actionParamComments) . "\n" ?>
* @return <?php echo $modelClass ?> the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel(<?php echo $actionParams ?>)
{
<?php
if (count($pks) === 1) {
$condition = '$id';
} else {
$condition = [];
foreach ($pks as $pk) {
$condition[] = "'$pk' => \$$pk";
}
$condition = '[' . implode(', ', $condition) . ']';
}
?>
if (($model = <?php echo $modelClass ?>::findOne(<?php echo $condition ?>)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
<?php
/**
* This is the template for generating CRUD search class of the specified model.
*/
use yii\helpers\StringHelper;
/* @var $this yii\web\View */
/* @var $generator yii\gii\generators\crud\Generator */
$modelClass = StringHelper::basename($generator->modelClass);
$searchModelClass = StringHelper::basename($generator->searchModelClass);
if ($modelClass === $searchModelClass) {
$modelAlias = $modelClass . 'Model';
}
$rules = $generator->generateSearchRules();
$labels = $generator->generateSearchLabels();
$searchAttributes = $generator->getSearchAttributes();
$searchConditions = $generator->generateSearchConditions();
echo "<?php\n";
?>
namespace <?php echo StringHelper::dirname(ltrim($generator->searchModelClass, '\\')) ?>;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use <?php echo ltrim($generator->modelClass, '\\') . (isset($modelAlias) ? " as $modelAlias" : "") ?>;
/**
* <?php echo $searchModelClass ?> represents the model behind the search form about `<?php echo $generator->modelClass ?>`.
*/
class <?php echo $searchModelClass ?> extends <?php echo isset($modelAlias) ? $modelAlias : $modelClass ?>
{
/**
* @inheritdoc
*/
public function rules()
{
return [
<?php echo implode(",\n ", $rules) ?>,
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = <?php echo isset($modelAlias) ? $modelAlias : $modelClass ?>::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
<?php echo implode("\n ", $searchConditions) ?>
return $dataProvider;
}
}
<?php
use yii\helpers\Inflector;
use yii\helpers\StringHelper;
/* @var $this yii\web\View */
/* @var $generator yii\gii\generators\crud\Generator */
/* @var $model \yii\db\ActiveRecord */
$model = new $generator->modelClass();
$safeAttributes = $model->safeAttributes();
if (empty($safeAttributes)) {
$safeAttributes = $model->attributes();
}
echo "<?php\n";
?>
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View */
/* @var $model <?php echo ltrim($generator->modelClass, '\\') ?> */
/* @var $form yii\bootstrap\ActiveForm */
?>
<div class="<?php echo Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-form">
<?php echo "<?php " ?>$form = ActiveForm::begin(); ?>
<?php echo "<?php echo " ?>$form->errorSummary($model); ?>
<?php foreach ($generator->getColumnNames() as $attribute) {
if (in_array($attribute, $safeAttributes)) {
echo " <?php echo " . $generator->generateActiveField($attribute) . " ?>\n\n";
}
} ?>
<div class="form-group">
<?php echo "<?php echo " ?>Html::submitButton($model->isNewRecord ? <?php echo $generator->generateString('Create') ?> : <?php echo $generator->generateString('Update') ?>, ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php echo "<?php " ?>ActiveForm::end(); ?>
</div>
<?php
use yii\helpers\Inflector;
use yii\helpers\StringHelper;
/* @var $this yii\web\View */
/* @var $generator yii\gii\generators\crud\Generator */
echo "<?php\n";
?>
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
/* @var $this yii\web\View */
/* @var $model <?php echo ltrim($generator->searchModelClass, '\\') ?> */
/* @var $form yii\bootstrap\ActiveForm */
?>
<div class="<?php echo Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-search">
<?php echo "<?php " ?>$form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?php
$count = 0;
foreach ($generator->getColumnNames() as $attribute) {
if (++$count < 6) {
echo " <?php echo " . $generator->generateActiveSearchField($attribute) . " ?>\n\n";
} else {
echo " <?php // echo " . $generator->generateActiveSearchField($attribute) . " ?>\n\n";
}
}
?>
<div class="form-group">
<?php echo "<?php echo " ?>Html::submitButton(<?php echo $generator->generateString('Search') ?>, ['class' => 'btn btn-primary']) ?>
<?php echo "<?php echo " ?>Html::resetButton(<?php echo $generator->generateString('Reset') ?>, ['class' => 'btn btn-default']) ?>
</div>
<?php echo "<?php " ?>ActiveForm::end(); ?>
</div>
<?php
use yii\helpers\Inflector;
use yii\helpers\StringHelper;
/* @var $this yii\web\View */
/* @var $generator yii\gii\generators\crud\Generator */
echo "<?php\n";
?>
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model <?php echo ltrim($generator->modelClass, '\\') ?> */
$this->title = <?php echo $generator->generateString('Create {modelClass}', ['modelClass' => Inflector::camel2words(StringHelper::basename($generator->modelClass))]) ?>;
$this->params['breadcrumbs'][] = ['label' => <?php echo $generator->generateString(Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass)))) ?>, 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="<?php echo Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-create">
<?php echo "<?php echo " ?>$this->render('_form', [
'model' => $model,
]) ?>
</div>
<?php
use yii\helpers\Inflector;
use yii\helpers\StringHelper;
/* @var $this yii\web\View */
/* @var $generator yii\gii\generators\crud\Generator */
$urlParams = $generator->generateUrlParams();
$nameAttribute = $generator->getNameAttribute();
echo "<?php\n";
?>
use yii\helpers\Html;
use <?php echo $generator->indexWidgetType === 'grid' ? "yii\\grid\\GridView" : "yii\\widgets\\ListView" ?>;
/* @var $this yii\web\View */
<?php echo !empty($generator->searchModelClass) ? "/* @var \$searchModel " . ltrim($generator->searchModelClass, '\\') . " */\n" : '' ?>
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = <?php echo $generator->generateString(Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass)))) ?>;
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="<?php echo Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-index">
<?php if(!empty($generator->searchModelClass)): ?>
<?php echo " <?php " . ($generator->indexWidgetType === 'grid' ? "// " : "") ?>echo $this->render('_search', ['model' => $searchModel]); ?>
<?php endif; ?>
<p>
<?php echo "<?php echo " ?>Html::a(<?php echo $generator->generateString('Create {modelClass}', ['modelClass' => Inflector::camel2words(StringHelper::basename($generator->modelClass))]) ?>, ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php if ($generator->indexWidgetType === 'grid'): ?>
<?php echo "<?php echo " ?>GridView::widget([
'dataProvider' => $dataProvider,
<?php echo !empty($generator->searchModelClass) ? "'filterModel' => \$searchModel,\n 'columns' => [\n" : "'columns' => [\n"; ?>
['class' => 'yii\grid\SerialColumn'],
<?php
$count = 0;
if (($tableSchema = $generator->getTableSchema()) === false) {
foreach ($generator->getColumnNames() as $name) {
if (++$count < 6) {
echo " '" . $name . "',\n";
} else {
echo " // '" . $name . "',\n";
}
}
} else {
foreach ($tableSchema->columns as $column) {
$format = $generator->generateColumnFormat($column);
if (++$count < 6) {
echo " '" . $column->name . ($format === 'text' ? "" : ":" . $format) . "',\n";
} else {
echo " // '" . $column->name . ($format === 'text' ? "" : ":" . $format) . "',\n";
}
}
}
?>
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
<?php else: ?>
<?php echo "<?php echo " ?>ListView::widget([
'dataProvider' => $dataProvider,
'itemOptions' => ['class' => 'item'],
'itemView' => function ($model, $key, $index, $widget) {
return Html::a(Html::encode($model-><?php echo $nameAttribute ?>), ['view', <?php echo $urlParams ?>]);
},
]) ?>
<?php endif; ?>
</div>
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment