2017 © Pedro Peláez
 

codeigniter-library ci-toastr

Codeigniter library for integrating javascript toastr

image

joshuachinemezu/ci-toastr

Codeigniter library for integrating javascript toastr

  • Thursday, June 21, 2018
  • by joshuachinemezu
  • Repository
  • 1 Watchers
  • 3 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

ci-toastr

Build Status, (*1)

A CodeIgniter Library to integrate javascript toastr, (*2)

Have you ever been in a situation that you need to send timed notifications to your client view, notifications that you want to expire within a certain period of time., (*3)

PHP(Codeigniter) allows that feature by flashing messages to the session but in most cases, the issue is to display such messages in a fashionable and user friendly way. Wooooh I got you on this. XD, (*4)

Example Scenario: You only just want to display the message with custom colors pertaining to each message This library will help you in runing such query in a very easy to use interface., (*5)

Requirements

  • PHP >= 5.2
  • CodeIgniter Application
  • Valid loading of the session library

Installation

The easiest way to install this is to clone the repo in your local disk. Then copy the src/Toaster.php file in your application/libraries Folder., (*6)

You can then load it like any other library, (*7)

$this->load->library('toastr');

Or if you are using composer run, (*8)

composer require joshuachinemezu/ci-toastr, (*9)

Create a file in your application/views folder and name it "alert.php". Paste the following code in it., (*10)

    <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css">


    <script type="text/javascript">


    <?php if ($this->session->flashdata('success')) {?>
        toastr.success("<?php echo $this->session->flashdata('success'); ?>");
    <?php } else if ($this->session->flashdata('error')) {?>
        toastr.error("<?php echo $this->session->flashdata('error'); ?>");
    <?php } else if ($this->session->flashdata('warning')) {?>
        toastr.warning("<?php echo $this->session->flashdata('warning'); ?>");
    <?php } else if ($this->session->flashdata('info')) {?>
        toastr.info("<?php echo $this->session->flashdata('info'); ?>");
    <?php }?>


    </script>

Ooooh it's getting complicated right? Don't worry one more step and we are done here, (*11)

Create another file in your application/views folder and name it flash.php (Just for consistency but you can name it anything if you know your way around here). Paste the code below in it, (*12)

    <!DOCTYPE html>
    <html>
    <head>
    <!-- <title>My Pages for Alert</title> -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet" />
    </head>
    <body>


    <div>
    <?php
    $this->load->view('alert');
    ?>
    </div>


    </body>
    </html>

Yeah we are through with installation. lol, (*13)

Usage

Using it is very easy, (*14)

In your controller after a task is completed, you can use any of the codes below in regards to the code flow, (*15)

-- for successful message, (*16)

    $this->toastr->success('Your account was created successfully');

-- for info message, (*17)

    $this->toastr->info('Please check your mail to activate account');

-- for warning message, (*18)

    $this->toastr->warning('Email is required');

-- for error message, (*19)

    $this->toastr->error('Error in creating account');

------- In the controller where you want the session(toastr) message to display, add --------the code below:, (*20)

    $this->load->view('flash');

-----** flash is the name of the file you created in application/views folder ***----, (*21)

Using the code above will display a toastr message, (*22)

You see very easy to use, (*23)

The Versions

21/06 2018

dev-master

9999999-dev

Codeigniter library for integrating javascript toastr

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joshua Chinemezu

composer library javascript codeigniter session toastr user interface