📕
Sprnva Docs
  • Introduction
  • What's New?
  • Installation
    • Requirements
    • Download Sprnva zip no composer required
    • Install Sprnva Using Composer
    • Setup Config
  • Deployment
  • File Structure
  • Database
    • Select
    • SelectLoop
    • Insert
    • Update
    • Delete
    • Query
    • Seeder
    • Paginate
    • With
    • andFilter
    • withCount
    • get
  • Query Builder
  • Migration
    • INSTANCES
      • NEW
      • RENAMETABLE
      • DROP
      • CHANGE
    • DUMPS
      • dump
      • dump prune
    • MAKE
    • MIGRATE
      • migrate
      • migrate fresh
    • ROLLBACK
  • Routing
    • with parameter
    • multiple parameters
    • with closure
    • group
    • controller grouping
  • Controllers
    • methods
  • Views
    • Passing Parameters
  • Validation
    • validate
      • validation type
  • Authentication
  • Alert Messages
  • Default Helpers
  • CSRF Protection
  • Email
  • Packages
    • Fortify
  • Themes and Templates
Powered by GitBook
On this page
  • Using alert_msg($status);
  • Using Error::any();

Alert Messages

Now we want users to know what's the status of their request by displaying an alert message.

PreviousAuthenticationNextDefault Helpers

Last updated 2 years ago

Using alert_msg($status);

Create a with_msg(["message" => ""]). Alert types example [ default, primary, success, warning, danger ] to give colors to the message to be shown.

After you set a with_msg() you can now show it to the views using the alert_msg() helper function. This helper function will display as alert and unset/removes the alert when refreshing the page.

How to display to views?

Just echo the alert_msg() helper function in your views like this.

  • Note: that the default color of the alert message is info

<?= alert_msg('danger') ?>

Using Error::any();

You can display errors using the loop to customized the looks of the alerts. Error:any() contains all the message produce by the applciation.

<?php if (!empty(Error::any())) { ?>
    <div class="alert alert-danger alert-dismissible fade show" role="alert">
        <?= implode("<br>", Error::any()) ?>
        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
<?php } ?>

when using this method, make sure the alert message is dismissable everytime you refresh the page. To do that we need to add a clear() method above the footer include at the bottom of our file.

  </div>
    </div>
</div>
<?php Error::clear() ?>
<?php require __DIR__ . '/../layouts/footer.php'; ?>