# yiicenter **Repository Path**: yuanxuegui/yiicenter ## Basic Information - **Project Name**: yiicenter - **Description**: An internet application skeleton, build in user center, admin backend, RESTful API and so on. - **Primary Language**: Unknown - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2015-09-12 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # YiiCenter Internet Application Skeleton An internet application skeleton, build in user center, admin backend, RESTful API and so on. It was created and developing as a fast start for building an advanced sites based on Yii2. It covers typical use cases for a new project and will help you not to waste your time doing the same work in every project ## TABLE OF CONTENTS - [Directory structure](#directory-structure) - [Users](#users) - [Features](#features) - [Installation](docs/installation.md) - [Application components](#application-components) - [Console commands](docs/console.md) - [Testing](docs/testing.md) - [FAQ](#faq) ##DIRECTORY STRUCTURE ``` common config/ contains shared configurations mail/ contains view files for e-mails models/ contains model classes used in both backend and frontend modules/ contains modules used in both backend and frontend console config/ contains console configurations controllers/ contains console controllers (commands) migrations/ contains database migrations models/ contains console-specific model classes runtime/ contains files generated during runtime backend assets/ contains application assets such as JavaScript and CSS config/ contains backend configurations controllers/ contains Web controller classes models/ contains backend-specific model classes runtime/ contains files generated during runtime views/ contains view files for the Web application web/ contains the entry script and Web resources frontend assets/ contains application assets such as JavaScript and CSS config/ contains frontend configurations controllers/ contains Web controller classes models/ contains frontend-specific model classes runtime/ contains files generated during runtime views/ contains view files for the Web application web/ contains the entry script and Web resources widgets/ contains frontend widgets api config/ contains api configurations modules/ contains versioned api modules runtime/ contains files generated during runtime web/ contains the entry script storage cache/ contains cache file config/ contains storage configurations web/ contains the entry script and upload files docs/ contains documents vendor/ contains dependent 3rd-party packages environments/ contains environment-based overrides tests contains various tests for the advanced application codeception/ contains tests developed with Codeception PHP Testing Framework ``` ## USERS `administrator` role account ``` Login: webmaster Password: webmaster ``` `manager` role account ``` Login: manager Password: manager ``` `user` role account ``` Login: user Password: user ``` ## FEATURES - Modularity support - Beautiful and open source dashboard theme for backend [AdminLTE 2](http://almsaeedstudio.com/AdminLTE) - Translations: Chinese, English - Translations Editor - Language change action + behavior to choose locale based on browser preferred language - Sign in, Sign up, profile(avatar, locale, personal data) etc - OAuth authorization - User management - RBAC with predefined `guest`, `user`, `manager` and `administrator` roles - RBAC migrations support - Content management components: articles, categories, static pages, editable menu, editable carousels, text blocks - Key-value storage component - Application settings form (based on KeyStorage component) - Ready-to-go RESTful API module - [File storage component + file upload widget](https://github.com/trntv/yii2-file-kit) - [Qiniu](http://developer.qiniu.com/) storage Support - On-demand thumbnail creation [trntv/yii2-glide](https://github.com/trntv/yii2-glide) - Useful behaviors (GlobalAccessBehavior, CacheInvalidateBehavior, MaintenanceBehavior) - Yii2 log web interface - Cache web controller - Maintenance mode component ([more](#maintenance-mode)) - System information web interface - `ExtendedMessageController` with ability to replace source code language and migrate messages between message sources - [Elfinder Extension](https://github.com/MihailDev/yii2-elfinder) - [Yii2 widgets](https://github.com/kartik-v/yii2-widgets) - Yii2 UEditor Extension - [Aceeditor widget](https://github.com/trntv/yii2-aceeditor) - Extended IDE autocompletion - Nginx config example - Test-ready - Docker support - Assets compression and concatenation - [Some useful shortcuts](common/shortcuts.php) - ... ## APPLICATION COMPONENTS ### I18N If you want to store application messages in DB and to have ability to edit them from backend, run: ``` php yii message/migrate @common/config/messages/php.php @common/config/messages/db.php ``` it will copy all existing messages to database Then uncomment config for `DbMessageSource` in ```php common/config/main.php ``` ### KeyStorage Key storage is a key-value storage to store different information. Application settings for example. Values can be stored both via api or by backend CRUD component. ``` Yii::$app->keyStorage->set('articles-per-page', 20); Yii::$app->keyStorage->get('articles-per-page'); // 20 ``` ### Maintenance mode YiiCenter has built-in component to provide a maintenance functionality. All you have to do is to configure ``maintenance`` component in your config ```php 'bootstrap' => ['maintenance'], ... 'components' => [ ... 'maintenance' => [ 'class' => 'common\components\maintenance\Maintenance', 'enabled' => Astronomy::isAFullMoonToday() ] ... ] ``` This component will catch all incoming requests, set proper response HTTP headers (503, "Retry After") and show a maintenance message. Additional configuration options can be found in a corresponding class. YiiCenter configured to turn on maintenance mode if ``frontend.maintenance`` key in KeyStorage is set to ``true`` ### Command Bus - [What is command bus?](http://shawnmc.cool/command-bus) In YiiCenter Command Bus pattern is implemented with [tactician](https://github.com/thephpleague/tactician) package and it's yii2 connector - [yii2-tactician](https://github.com/trntv/yii2-tactician) Command are stored in ``common/commands/command`` directory, handlers in ``common/commands/handler`` To execute command run ```php $sendEmailCommand = new SendEmailCommand(['to' => 'user@example.org', 'body' => 'Hello User!']); Yii::$app->commandBus->handle($sendEmailCommand); ``` ### Behaviors #### CacheInvalidateBehavior ```php public function behaviors() { return [ [ 'class' => `common\behaviors\CacheInvalidateBehavior`, 'tags' => [ 'awesomeTag', function($model){ return "tag-{$model->id}" } ], 'keys' => [ 'awesomeKey', function($model){ return "key-{$model->id}" } ] ], ]; } ``` #### GlobalAccessBehavior Add in your application config: ```php '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'] ], [ 'allow' => true, 'roles' => ['@'] ] ] ] ``` It will allow access to you application only for authentificated users. ### Widgets configurable from backend #### Carousel 1. Create carousel in backend 2. Use it: ```php 'key-from-backend']) ?> ``` #### DbText 1. Create text block in backend 2. Use it: ```php 'key-from-backend']) ?> ``` #### DbMenu 1. Create text block in backend 2. Use it: ```php 'key-from-backend']) ?> ``` ### Widgets - UEditor - [Ace Editor](https://github.com/trntv/yii2-aceeditor) - [File upload](https://github.com/trntv/yii2-file-kit) - [ElFinder](https://github.com/MihailDev/yii2-elfinder) ### Grid #### EnumColumn ```php [ 'class' => '\common\grid\EnumColumn', 'attribute' => 'status', 'enum' => User::getStatuses() // [0=>'Deleted', 1=>'Active'] ] ``` ### API YiiCenter has fully configured and ready-to-go REST API module. You can access it on http:///api.yiicenter.net/v1 ### MultiModel ``common\base\MultiModel`` - class for handling multiple models in one In controller: ```php $model = new MultiModel([ 'models' => [ 'user' => $userModel, 'profile' => $userProfileModel ] ]); if ($model->load(Yii::$app->request->post()) && $model->save()) { ... } ``` In view: ```php field($model->getModel('account'), 'username') ?> field($model->getModel('profile'), 'realname')->textInput(['maxlength' => 20]) ?> ``` ### Other - ``common\behaviors\GlobalAccessBehavior`` - allows to set access rules for your application in application config - ``common\behaviors\LocaleBehavior`` - discover user locale from browser or account settings and set it - ``common\behaviors\LoginTimestampBehavior`` - logs user login time - ``common\validators\JsonValidator`` - validates a value to be a valid json - ``common\rbac\OwnModelRule`` - simple rule for RBAC to check if the current user is model owner ##FAQ ###Where is Gii? Gii is available on: - http://www.yiicenter.net/gii - http://admin.yiicenter.net/gii ###How to contribute? You can contribute in any way you want. mail to [yuanxuegui@163.com](mailto:yuanxuegui@163.com) ##READ MORE - https://github.com/yiisoft/yii2-app-advanced/blob/master/README.md - https://github.com/yiisoft/yii2/tree/master/docs