PHP code example of loveorigami / yii2-notification-wrapper

1. Go to this page and download the library: Download loveorigami/yii2-notification-wrapper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

loveorigami / yii2-notification-wrapper example snippets


public function actionIndex(){
    ...
     Yii::$app->session->setFlash('error',   'noty error');
     Yii::$app->session->setFlash('info',    'noty info');
     Yii::$app->session->setFlash('success', 'noty success');
     Yii::$app->session->setFlash('warning', 'noty warning');
    ...
     return $this->render('index');
 }

 // or in ajax action

 public function actionAjax(){
     ...
     Yii::$app->session->setFlash('error',   'ajax error');
     Yii::$app->session->setFlash('info',    'ajax info');
     Yii::$app->session->setFlash('success', 'ajax success');
     Yii::$app->session->setFlash('warning', 'ajax warning');
     ...
     $data = 'Some data to be returned in response to ajax request';
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return $data;
  }
 

'modules' => [
    'noty' => [
        'class' => 'lo\modules\noty\Module',
    ],
],

use lo\modules\noty\Wrapper;

// for Bootstrap Alert
echo Wrapper::widget();

// or for Growl
echo Wrapper::widget([
    'layerClass' => 'lo\modules\noty\layers\Growl',
]);

// or for Noty
echo Wrapper::widget([
    'layerClass' => 'lo\modules\noty\layers\Noty',
]);

use lo\modules\noty\Wrapper;

echo Wrapper::widget([
    'layerClass' => 'lo\modules\noty\layers\Noty',
    'layerOptions'=>[
        // for every layer (by default)
        'layerId' => 'noty-layer',
        'customTitleDelimiter' => '|',
        'overrideSystemConfirm' => true,
        'showTitle' => true,

        // for custom layer
        'registerAnimateCss' => true,
        'registerButtonsCss' => true
    ],

    // clientOptions
    'options' => [
        'dismissQueue' => true,
        'layout' => 'topRight',
        'timeout' => 3000,
        'theme' => 'relax',

        // and more for this library...
    ],
]);


    echo  Wrapper::widget([
        'layerClass' => '...',
        'layerOptions' => [
            'customTitleDelimiter' = '|', // by default
        ],
    ]);

public function actionIndex(){
    ...
     Yii::$app->session->setFlash('success', 'CUSTOM TITLE | noty success');
    ...
 }

// In layout:
    $layerParams = [
        'layerClass' => '...',
        'layerOptions' => [
            ...
        ],
    ];
    
    if (isset($this->params['layerParams']){
        $layerParams = \yii\helpers\ArrayHelper::merge($layerParams, $this->params['layerParams']);
    }
    echo  Wrapper::widget($layerParams);
    
    
// In view:
    $this->params['layerParams'] = [
        'layerClass' => 'lo\modules\noty\layers\Alert',
        'layerOptions' => [
            'layerId' => 'my-noty-id',
        ],
    ];
 
    echo '<div id="my-noty-id"></div>'; // and notification will be placed here

    Pjax::begin([
        'clientOptions' => [
            'showNoty' => false
        ]
    ]); 
    ... pjax container ...
    Pjax::end(); 

use lo\modules\noty\exceptions\NotyFlashException;
use lo\modules\noty\exceptions\NotyErrorException;

public function actionUpdate($id)
{
    $model = $this->findModel($id);

    try {
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('update', [
                'model' => $model,
            ]);
        }
    } catch (NotyFlashException $e) {
        $e->catchFlash();
    }
}
    
protected function findModel($id)
{
    if (($model = Post::findOne($id)) !== null) {
        return $model;
    } else {
        throw new NotyErrorException('The requested page does not exist.');
    }
}
bash
$ php composer.phar php composer.phar query-growl "^1.3"