📜 ⬆️ ⬇️

Codeigniter Notify (UPD: 06/16/12)

Good night, habra people.
I would like to share with you a self-made library for codeigniter called Notify.
It is designed to display messages to the user.


Just a bit of history

The library is a little more than six months. In her first submission she was still a helper and for the self-written crm which I wrote then.
Later I switched to codeigniter and dragged it along.
Since then, pulling from project to project. It suits me, maybe someone will also be useful.

Very little description

I repeat that the library was created to display messages to the user.
Basic styles and necessary js-scripts are included directly in the text of the php file. Made it for your own convenience.
Depending on whether the page is asynchronously requested or not, the response will be recorded in the session, or returned in json format.
You can return one message or queue. Messages can be of different types.
You can insert messages into the queue and redirect, or you can insert them into the queue before loading the view, and they will be shown right there. The messages added by javascript, both parsed from the server response and added directly from the js code, look identical.
You can send the data or the redirect address with the response.
')
Installation

  1. Download codeigniter-notify-library from github
    Download from github

  2. The library has two files, one will go to the / application / config folder, the second to / application / libraries /
  3. Connect the library via autoload.php or directly to the controller via load-> library
  4. After that and change the main / main views


<html> <head> ... <?=$this->notify->initJsCss()?> <!--  -   ,   --> </head> <body> <?=$this->notify->getMessages()?><!--   --> ... </body> </html> 


Example of using php:

  function some_action() { if ($result) { $this->notify->error('   '); $this->notify->setData( json_encode(array('sum_count' => 4)) ); $this->notify->returnSuccess(' '); } else $this->notify->returnError(' - '); } 


Example usage in js:

 $.post(url,form_data,function(data) { var json = $.parseJSON(data); if (notifyIsSuccess(json)) { $(".sum").text(json.data.sum_count); notifySuccess('   '); } notify(json); //   ,    }); 


Basic methods

  //     $this->notify->error(' - '); // php notifyError('   '); // js //      $this->notify->success('    '); // php notifySuccess('    '); // js //     //  javascript      data   $this->notify->setData( json_encode(array('item' => 'value')) ); //    ,       php, //      window.location $this->notify->setComeback( site_url() ); //       $this->notify->returnNotify(); 


Dependencies:



UPD, about the css and js hardcode

I knew that it would not be accepted with a bang) Believe me, this is not from illiteracy (well, I want to hope so :)). I will try to explain why this was done.
At the beginning of work on the library of edits there were many minor edits. And it was used at the same time then on several projects, two or three, I definitely don’t remember. Synchronization in the code changes caused, I am sorry, the strongest butthurt. I already wrote above that everything was merged into one file for my own convenience.
At this stage there is not a lot of edits, and I think I can finally separate the flies from the chops)

Comments, pros, cons, forks - I will be glad of any reaction.
Thank.

For those who are looking for links to download at the bottom of the post:
link to repository has been changed from
github.com/antongorodezkiy/codeigniter-notify-library
on
github.com/antongorodezkiy/notify-library
Download from github

UPD from 03/26/12

Library updated. Removed one critical bug that made the work of the library impossible.
Also added is the mustDie method, allowing / disallowing the library to interrupt script execution after the return * methods. It is made for use in modules (for example, HMVC), in my case, for example:

 ... $this->notify->mustDie(false); $result = Modules::run('admin/programs_offers/attach'); //      $this->notify->returnError(); $this->notify->mustDie(true); if ($result) $this->notify->returnSuccess('  '); 


UPD from 06/16/12

Library updated.
 //      (ttl), 0 -     ,       $this->notify->returnError(' - ',0); //         setTtl(),   $this->notify->setTtl(4); //       ,    setSilence() $this->notify->setSilence(true); $this->notify->returnError(' - '); //      $this->notify->setSilence(false); $this->notify->returnError('   - '); //     //     ,          //       $this->notify->getMessages(); //     ,         //    getMessages()   ,            // controller: $this->notify->error(' 1'); ... $this->notify->error(' 2','',' '); // view: $this->notify->getMessages(); //    1,  2    ... $this->notify->getMessages(' '); //    2 

Source: https://habr.com/ru/post/140293/


All Articles