File: docs/extensions/Messages.md

Recommend this page to a friend!
  Classes of Slawomir Kaleta  >  Dframe Framework  >  docs/extensions/Messages.md  >  Download  
File: docs/extensions/Messages.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: Dframe Framework
Modular MVC based PHP Web framework
Author: By
Last change:
Date: 1 year ago
Size: 1,990 bytes
 

Contents

Class file image Download

Dframe\Messages

Is a helpful class It helps to quickly add to the session messages that may display user

You have two type params for adding (First) and for display (Second) message. First type consists of e, s, w, i and second of error, success, warning, info

Methods example #1

Just display after add.

use Dframe\Messages;
use Dframe\Session;

include_once 'vendor/autoload.php';

$msg = new Messages(new Session('hashSaltRandomForSession')); // Join the current session
$msg->add('s', 'Success Message!');
//$msg->add('s', 'Success Message!', 'page/index'); // with redirect 
$msg->hasMessages('success'): // Will return ['success']
$msg->hasMessages(): // Will return all array

$msg->clear('success'); // remove success msg
$msg->clear(); // remove all msg

var_dump($msg->display('success'));

Methods example #2*

Set message and refresh/redirect

use Dframe\Messages;
use Dframe\Router;
use Dframe\Session;

include_once 'vendor/autoload.php';

$router = new Router();
$msg = new Messages(new Session('hashSaltRandomForSession')); // Join the current session

if(!empty($msg->hasMessages())){
   var_dump($msg->display('success'));
   var_dump($msg->display('error'));
   var_dump($msg->display('info'));
   var_dump($msg->display('warning'));
   die();
}

$msg->add('s', 'Success Message!'); 
$msg->add('e', 'Error Message!'); 
$msg->add('i', 'Info Message!'); 
$msg->add('w', 'Warning Message!');

$router->redirect('page/index');

*Not Recommended if you have just one msg and after that you break code return and redirect client to other page

Methods example #3

use Dframe\Messages;
use Dframe\Session;

include_once 'vendor/autoload.php';

$msg = new Messages(new Session('hashSaltRandomForSession')); // Join the current session

if(isset($msg->hasMessages())){
   var_dump($msg->display('success'));
   die();
}

$msg->add('s', 'Success Message!', 'page/index');
return;


For more information send a message to info at phpclasses dot org.