Tag: codeigniter

  • How To Catch PHP Fatal Error In CodeIgniter

    My last few blog post’s are result of the project that I am currently working on, and this blog is also in that series.

    We needed to catch PHP Fatal Errors in the production environment and notify about it to developers, also at the same time, showing our beautiful fail whale page to user instead of ugly error or a white screen of death.

    Here I will show you how to do this in CodeIgniter, though credit for this idea goes to hipertracker.

    First of all you will need to setup a hook, so update your hooks.php file with following code

    	$hook['pre_system'][] = array(
    	    'class'    => 'PHPFatalError',
                'function' => 'setHandler',
                'filename' => 'PHPFatalError.php',
       	    'filepath' => 'hooks'
    );

    Now put the code shown below in PHPFatalError.php file in your applications hooks folder.

    This is the simplifed version of what I have done, so please update handleShutdown function as per your needs.

    Check out PHPCamp a place to share news, views and articles that are useful to PHP community.
  • Simple Way To Add Global Exception Handling In CodeIgniter

    I am working on a project where we needed to capture exceptions at a global level instead of doing it at every step as they were not critical, but important for us to know.

    The idea was that whenever such an exception occur on production we should send an email to developers mailing list so that someone can investigate it.

    As usual I did a quick google search and i found two forum posts in CodeIgniter and one on stackoverflow, but they all fall short as CodeIgniter does not set’s any default exception handlers they way it sets the native error handler.

    So here is a quick tutorial on how you can do that.
    (more…)

  • CodeIgniter 2.0 Is Baking

    Just when I was loosing all hopes about CodeIgniter, yesterday EllisLab announced about their move to assembla and mercurial, in that there was a small but significant news about CodeIgniter 2.0.

    A quick look into the change log revealed

    PHP 4 support is deprecated.  Features new to 2.0.0 may not be support PHP 4, and all legacy features will no longer support PHP 4 as of 2.1.0.

    This is what I was waiting for. What it means, as pointed by Phil Sturgeon and Elliot Haughin, is that CI 2.0 will not run on PHP 4, but more importantly, it can now take full advantages of PHP 5.

    One other thing that I liked is

    Added ability to set "Package" paths - specific paths where the Loader and Config classes should try to look first for a requested file.  This allows distribution of sub-applications with their own libraries, models, config files, etc. in a single "package" directory.  

    Which means that now we can create common area where we can keep helpers, views and libraries that needs to be shared between two applications.

    While there are many more updates these two got me excited.

    For now let’s wait for them to release, meanwhile you can sign up for Bitbucket and follow the updates for CodeIgniter Project.

  • Integrating With Twitter API In CodeIgniter

    I needed to integrate Twitter API in one  of my web applications which uses CodeIgniter framework.

     

    As their is no direct library available in CI for twitter integration, at first go this might look very difficult, but it is really simple.

     

    Here is how you can do it..

    1. First download the  Twitter class for PHP.
    2. Put the class.twitter.php file in application/libraries folder.
    3. Rename class.twitter.php to twitter.php ( to make it compatible with CI naming conventions).
    4. Open twitter.php file and set following variables
    var $username=’'; //twitter username
    var $password=''; // twitter password
    var $user_agent=''; //an identifier for twitter preferably email address
    Are you satisfied with your knowledge? No, then spent 15 minutes every day on PHPCamp.net a knowledge sharing website for our own PHP community

    If you have followed these steps your integration is almost complete, now all you need to do is use the twitter library, here is an example to get you started 🙂

     $this->load->library('Twitter');
     $msg=’Just Integrated Twitter with CodeIgniter ’;
     $this->twitter->update($msg);

    By the way you can follow me on twitter @thecancerus.

  • CodeIgniter is the fastest PHP framework

    Ekerete Akpan, from AVNet Labs, released the results of his small experiment to measure the performance of four PHP frameworks.He used requests/sec as a performance yardstick, what it tells is that number of request your webserver can handle, if you use one of these frameworks.php-framework-comparison-benchmarksAnd the result of all his test says that between Zend Framework,CakePHP and CodeIgniter, CodeIgniter is the fastest one.This test validates my choice for going with CI as framework, instead of Zend.For detailed analysis checkout the original post.Update: Even Rasmus Lerdorf prefers CI over all the frameworks avilable.