Giter VIP home page Giter VIP logo

codeigniter-fluent-sessions's Introduction

Fluent Sessions for CodeIgniter

What does 'Fluent' mean?

A 'Fluent' API is one that takes advantage of language features to make using said API less of a chore, and, many times, more self-descriptive. A fluent API attempts to require the user to only use as little of the parent language as possible to describe what they are wanting to do.

What does Fluent Sessions for CodeIgniter bring to the table?

Fluent Sessions has two functions:

  • Provide an alternate API to smooth over the wrinkles in the userdata and flashdata API of the standard CodeIgniter session class.
  • Provide standard mechanism for classifying flashdata into three categories:
    • Notices: Good things; Success messages.
    • Messages: Generic message of neutral information
    • Warnings: Report bad things such as errors or bad form input.

Examples of the alternative syntax

Standard Session:

$this->session->set_userdata('key', 'value');
$key = $this->session->userdata('key');
$this->session->set_userdata('another_key', 'another value');
$this->session->unset_userdata('key');
$this->session->unset_userdata('another_key');
$this->session->set_flashdata('flashkey', 'flashvalue');
$this->session->sess_destroy();

Fluent Session:

$this->session->key = 'value';
$key = $this->session->key;
$this->session->another_key = 'another value';
$this->session->clear();
$this->session->flash->flashkey = 'flashvalue';
$this->session->destroy();

Note the differences in the two code samples above. The standard CI Session class requires you to pollute your intention with function calls just to set and get data from the session. Fluent Sessions, on the other hand, uses a clearer syntax to set a key/value pair.

Fluent Session flash categories:

Example controller code:

$this->session->flash->warnings['username'] = 'Cannot be blank';
$this->session->flash->warnings['passwords'] = 'Must match';

Example view code:

<?php if (count($this->session->flash->warnings)): ?>
    <ul>
        <?php foreach ($this->sessions->flash->warnings as $field => $message): ?>
            <li><?php echo $field ?>: <?php echo $message ?></li>
        <?php endforeach ?>
    </ul>
<?php endif ?>

Generates:

<ul>
    <li>username: Cannot be blank</li>
    <li>passwords: Must match</li>
</ul>

Due to these being part of flash data, just like any other flash data, they will only persist for one subsequent page load.

Installation:

Copy libraries/MY_Session into your application/libraries directory.

codeigniter-fluent-sessions's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.