dev-master
9999999-devflash messages
MIT
The Requires
- php >=5.4.0
- phpixie/slice ~3.0
- phpixie/http ~3.0
The Development Requires
by Kostya Nemchenko
messages flash phpixie
Wallogit.com
2017 © Pedro Peláez
flash messages
Flash messages for phpixie3, (*1)
1) Подключаем библиотеку в проект, (*2)
composer require koka/flash:dev-master
2) Подключить библиотеку глобально для всех бандлов, (*3)
// /src/Project/Framework/Builder.php
protected function buildComponents()
{
return new Components($this);
}
```php // /src/Project/Framework/Components.php, (*4)
namespace Project\Framework;, (*5)
class Components extends \PHPixie\BundleFramework\Components { public function flash() { return $this->instance('flash'); }, (*6)
protected function buildFlash()
{
$types = $this->builder->assets()->configStorage()->get('flash');
if (!$types) {
$types = [];
}
return new \Koka\Flash\Flash($this->builder->context(), $types);
}
}, (*7)
### Для кастомизации типов создайте файл
Значения массива можно изменять под свои нужды, главное сохранять ключи.
Если файл не создавать то по умолчанию тип равен ключу.
```php
// /assets/config/flash.php
'alert alert-error',
'danger' => 'alert alert-danger',
'warning' => 'alert alert-warning',
'notice' => 'alert alert-notice',
'alert' => 'alert alert-alert',
'info' => 'alert alert-info',
'success' => 'alert alert-success'
];
```
### Использование
```php
// /bundles/app/src/Project/App/HTTPProcessor.php
namespace Project\App;
class HTTPProcessor extends \PHPixie\DefaultBundle\Processor\HTTP\Builder
{
protected $builder;
protected $attribute = 'processor';
public function __construct($builder)
{
$this->builder = $builder;
}
protected function buildGreetProcessor()
{
return new HTTPProcessors\Greet($this->builder);
}
}
```
```php
// /bundles/app/src/Project/App/HTTPProcessors/Greet.php
namespace Project\App\HTTPProcessors;
class Greet extends \PHPixie\DefaultBundle\Processor\HTTP\Actions
{
protected $template;
protected $flash;
public function __construct($builder)
{
$this->template = $builder->components->template();
$this->flash = $builder->components->flash();
}
public function defaultAction($request)
{
// add test info message
$this->flash->info('Test info message');
$container = $this->template->get('app:greet');
$container->message = "Have fun coding!";
$container->flash = $this->flash;
return $container;
}
}
```
```php
// /bundles/app/assets/templates/layout.php
PHPixie 3.0
PHPixie 3.0
<div class="<?=$msg->getType()?>" role='alert'><?=$_($msg)?></div>
<?php endforeach;?>
</div>
<?php $this->childContent();?>
</body>
</html>
flash messages
MIT
messages flash phpixie