PHP code example of gajus / paddy

1. Go to this page and download the library: Download gajus/paddy 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/ */

    

gajus / paddy example snippets


/**
 * @param string $namespace Namespace is used if more than one application is using Messenger. Defaults to the SERVER_NAME or "default".
 */
$messenger = new \Gajus\Paddy\Messenger();

/**
 * @param string $message
 * @param string $namespace Message namespace (success, error or notice).
 * @return $this
 */
$messenger->send('Loaded to the Gunwales!');

$messenger->send('There is more grog on the deck!', 'success');

/**
 * Return all messages nested under the respective message namespace.
 * 
 * @return array
 */
$messenger->getMessages();

/**
 * Check if there are messages under the specified message namespace.
 * 
 * @param string $namespace
 * @return boolean
 */
$messenger->has('error');

$messenger->send('a');
$messenger->send('b', 'success');

echo $messenger->getMessageHolder();

/**
 * Shorthand method to send message under "error" namespace.
 *
 * @param string $message
 * @return $this
 */
public function error ($message) {
    return $this->send($message, 'error');
}

/**
 * Shorthand method to send message under "success" namespace.
 *
 * @param string $message
 * @return $this
 */
public function success ($message) {
    return $this->send($message, 'success');
}

/**
 * Shorthand method to send message under "notice" namespace.
 *
 * @param string $message
 * @return $this
 */
public function notice ($message) {
    return $this->notice($message, 'notice');
}

// Page 1
$messenger->error('foo');

// Page 2
header('Location: Page 3');

// Page 3
var_dump($messenger->has('error'));

array(1) {
  [0]=>
  bool(true)
}