Basic starting platform with simple user functions(auth, registration, password change etc..) and RBAC.
Contains modules:
admin/ admin module for users/articles/notifications managment
main/ main module for users
user/ contains functionality for user
The minimum requirement by this project template that your Web server supports PHP 5.4.0. MySQL database.
php yii migrate/up
php yii rbac/init
php yii roles/assign
Also revoke available.
php yii users/create
...
See actions of app\commands\UserController.php
Edit the file config/db.php
with real data, for example:
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2basic',
'username' => 'root',
'password' => '1234',
'charset' => 'utf8',
];
//include events traits
use EventsTrait;
use EventsHandlersTrait;
...
//init handlers (for example in init function), you can overwrite them if needed
public function init()
{
parent::init();
$this->initArticleHandlers($this);//you can init only specific events or all
}
//trigger event where you need it
//you need to pass appropriate model for event
$event = $this->getArticleEvent($this);
$this->trigger($event::ARTICLE_CREATED,$event);
* Create new event class which implements EventInterface
* Add new event to EventsTrait
* Create handler init in EventsHandlersTrait
* Append events available to admin/notifications/_form dropdownList
```php
//add constant
const ARTICLE_CREATED = 'articleCreated';
//add to eevents array
public static function getEvents()
{
return [
self::ARTICLE_CREATED => self::ARTICLE_CREATED,
self::ARTICLE_UPDATED => self::ARTICLE_UPDATED
];
}
```
After that you can create notification for event and attach to your models.
```php
//append Notifications
static $_types = [
1 => 'email',
2 => 'browser'
];
...
```
Add new type to handling function in EventsHandlersTrait
:
```php
...
switch(Notifications::$_types[$type]){
case 'email':
$notification->sendEmailNotification($event->getModel(),$event->getTokens());
break;
case 'browser':
$notification->addToBrowserQuery($event->getModel(),$event->getTokens());
break;
default:
$event->handled = true;
break;
}
...
```
Overwrite getTokens()
and getTokensForView()
functions in your model.
@TODO