Example #1
0
 /**
  * Wrapper for flash object to be used as global function.
  *
  * @param string            $message  - message text
  * @param string            $type     - message type: success, info, warning, error
  * @param TemplateInterface $template - template (optional)
  *
  * @return Flash
  */
 function flash($message = '', $type = 'info', TemplateInterface $template = null)
 {
     $flash = new Flash($template);
     if (!empty($message)) {
         return $flash->message($message, $type);
     }
     return $flash;
 }
Example #2
0
 public static function save_place()
 {
     $flash = new Flash();
     $post_data = Flight::request()->data;
     // recaptcha
     $secret = getenv('RECAPTCHA_SECRET');
     $gRecaptchaResponse = $post_data['g-recaptcha-response'];
     $recaptcha = new ReCaptcha($secret);
     $resp = $recaptcha->verify($gRecaptchaResponse, $_SERVER['REMOTE_ADDR']);
     if ($resp->isSuccess()) {
         // verified!
         $address = "{$post_data['calle']} {$post_data['altura']}, {$post_data['ciudad']}, {$post_data['provincia']}, Argentina";
         // save new place
         Place::create(array('name' => $post_data['name'], 'address' => $address, 'start_hour' => $post_data['start_hour'], 'end_hour' => $post_data['end_hour'], 'days' => $post_data['days'], 'comments' => $post_data['comments']));
         $flash->message('success');
     } else {
         $errors = $resp->getErrorCodes();
         $flash->message('error');
     }
     Flight::redirect('/', 302);
 }
use App\Http\Model\Blog;
use Tamtamchik\SimpleFlash\Flash;
$app->group('/articles', function () use($app) {
    /**
     * Article getIndex
     */
    $app->get('/', function () use($app) {
        $flash = new Flash();
        $blog = Blog::latest()->get();
        $app->render('site/articles/article.php', ['blog' => $blog, 'flash' => $flash->display()]);
    })->name('article.index');
    /**
     * Article getCreate
     */
    $app->get('/create', function () use($app) {
        $flash = new Flash();
        $flash->info('Create Message.');
        $app->render('site/articles/create.php', ['flash' => $flash->display()]);
    })->name('article.create');
    /**
     * Article postCreate
     */
    $app->post('/create', function () use($app) {
        $rules = ['title' => ['required', 'min_length(3)'], 'content' => ['required']];
        $input = ['title' => $app->request->post('title'), 'content' => $app->request->post('content')];
        $validation_result = \SimpleValidator\Validator::validate($_POST, $rules);
        if ($validation_result->isSuccess()) {
            $blog = new Blog();
            $blog->title = $app->request->post('title');
            $blog->content = $app->request->post('content');
            $blog->save();