holabs/flashes

Flash messages extension for Nette Framework

1.0.1 2017-11-22 07:25 UTC

This package is auto-updated.

Last update: 2024-10-20 01:16:44 UTC


README

Installation

Require:

composer require holabs/flashes

Configuration

extensions:
	flashes: Holabs\Flashes\Bridges\Nette\FlashesExtension

Using

BasePresenter class:

use Nette\Application\UI\Presenter;
use Holabs\Flashes\Message;
use Holabs\Flashes\UI\IFactory;
use Holabs\Flashes\UI\Control;

class BasePresenter extends Presenter {

	use TFlasher; // Inject flash factory
	
	/** @var IFactory @inject */
	public $flashesControlFactory; // Optional
	
	public function actionDefault(){
	    $this->flashMessage('Hello world!', Message::$INFO);
	    $this->flashMessage('Hello world with link!', Message::$INFO)
	    	->setLink($this->link('link'), 'Nice link');
	}
	
	// Optional component
	
	/**
	 * @return Control
	 */
	protected function createComponentFlashes(){
		$control = $this->flashesControlFactory->create($this);
		// $control->setTemplateFile('path/to/your/latte')
		return $control;
	}
	
	// ...

}

@layout.latte file:

	{* ... *}
	
	{* Standard render *}
	<div n:foreach="$messages as $message" class="flash flash-{$message->getType()}">
    	{$message->getMessage()}.
    	<a href="{$message->getLink()->url}" n:if="$message->getLink()">{$message->getLink()->text}</a>
    </div>
    
    {* OR control *}
	{control flashes}
	
	{* ... *}