This is Yii2 start application template.
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
Please, consider helping project via contributions or (donations)[#donations].
##DEMO Frontend: http://yii2-starter-kit.terentev.net
Backend: http://backend.yii2-starter-kit.terentev.net
administrator
role account
Login: webmaster
Password: webmaster
manager
role account
Login: manager
Password: manager
user
role account
Login: user
Password: user
guest
, user
, manager
and administrator
rolesExtendedMessageController
with ability to replace source code language and migrate messages between message sourcesIf you want to store application messages in DB and to have ability to edit them from backend, run:
php console/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
common/config/base.php
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
Starter kit has built-in component to provide a maintenance functionality. All you have to do is to configure maintenance
component in your config
'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.
Starter kit configured to turn on maintenance mode if frontend.maintenance
key in KeyStorage is set to true
In Starter Kit Command Bus pattern is implemented with tactician package and it's yii2 connector - yii2-tactician
Command are stored in common/commands/command
directory, handlers in common/commands/handler
To execute command run
$sendEmailCommand = new SendEmailCommand(['to' => 'user@example.org', 'body' => 'Hello User!']);
Yii::$app->commandBus->handle($sendEmailCommand);
$addToTimelineCommand = new AddToTimelineCommand([
'category' => 'user',
'event' => 'signup',
'data' => ['foo' => 'bar']
]);
Yii::$app->commandBus->handle($addToTimelineCommand);
public function behaviors()
{
return [
[
'class' => `common\behaviors\CacheInvalidateBehavior`,
'tags' => [
'awesomeTag',
function($model){
return "tag-{$model->id}"
}
],
'keys' => [
'awesomeKey',
function($model){
return "key-{$model->id}"
}
]
],
];
}
Add in your application config:
'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.
<?php echo DbCarousel::widget(['key' => 'key-from-backend']) ?>
<?php echo DbText::widget(['key' => 'key-from-backend']) ?>
<?php echo DbMenu::widget(['key' => 'key-from-backend']) ?>
[
'class' => '\common\grid\EnumColumn',
'attribute' => 'status',
'enum' => User::getStatuses() // [0=>'Deleted', 1=>'Active']
]
Starter Kit has fully configured and ready-to-go REST API module. You can access it on http://yii2-starter-kit.dev/api/v1
common\base\MultiModel
- class for handling multiple models in one
In controller:
$model = new MultiModel([
'models' => [
'user' => $userModel,
'profile' => $userProfileModel
]
]);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
...
}
In view:
<?php echo $form->field($model->getModel('account'), 'username') ?>
<?php echo $form->field($model->getModel('profile'), 'middlename')->textInput(['maxlength' => 255]) ?>
common\behaviors\GlobalAccessBehavior
- allows to set access rules for your application in application configcommon\behaviors\LocaleBehavior
- discover user locale from browser or account settings and set itcommon\behaviors\LoginTimestampBehavior
- logs user login timecommon\validators\JsonValidator
- validates a value to be a valid jsoncommon\rbac\OwnModelRule
- simple rule for RBAC to check if the current user is model owner##FAQ
Gii is available on:
##How to contribute? You can contribute in any way you want. Any help appreciated, but most of all i need help with docs (^_^)
##Donations
##Have any questions? mail to eugene@terentev.net
##READ MORE https://github.com/yiisoft/yii2/blob/master/apps/advanced/README.md https://github.com/yiisoft/yii2/tree/master/docs
###NOTE This template was created mostly for developers NOT for end users. This is a point where you can begin your application, rather than creating it from scratch. Good luck!
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。