CodeIgniter - An MVC framework for PHP

CodeIgniter - An MVC framework for PHP

I have been using CodeIgniter since some time and used in couple of my projects. It’s a good and easy to use PHP MVC Framework, which takes you on the road very quickly and you start developing real time application with it. For any experienced PHP Programmer it’s matter of few hours to start working with CI and get started-on with production.

It’s got decent documentation (User Guide, Wiki and Community support forum). No configuration and no command-lines. Last release was way back in September’09 and I heard something about v1.8 sometime after that. But now it has been more than 1 year and recently while going through news section on CI website I read a post stating that new version of framework CI2 is about to be released.

I got excited and downloaded a copy from bitbucket. I was happy to see that CodeIgniter2 will be dropping PHP4 support step by step. There are lot of new changes/additions which you might be interested in if you’re day-to-day CI user. Ellislab being professional company CI2 has been already used in their newer version of ExpressionEngine.

Here are some of the changes I have grabbed from CodeIgniter2 User Guide:

  • General changes
    • PHP 4 support is deprecated. Features new to 2.0.0 may not support PHP 4, and all legacy features will no longer support PHP 4 as of 2.1.0. (Good)
    • Scaffolding, having been deprecated for a number of versions, has been removed.
    • Plugins have been removed, in favor of Helpers. The CAPTCHA plugin has been converted to a Helper and documented. The JavaScript calendar plugin was removed due to the ready availability of great JavaScript calendars, particularly with jQuery.
    • Added new special Library type: Drivers.
    • Moved the application folder outside of the system folder. (I liked this)
    • Added routing overrides to the main index.php file, enabling the normal routing to be overridden on a per “index” file basis.
    • Added the ability to set config values (or override config values) directly from data set in the main index.php file. This allows a single application to be used with multiple front controllers, each having its own config values.
    • Added $config['directory_trigger'] to the config file so that a controller sub-directory can be specified when running _GET strings instead of URI segments.
    • 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. See the Loader class documentation for more details.
    • In-development code is now hosted at BitBucket. (Go grab your copy)
    • Removed the deprecated Validation Class.
  • Libraries
    • Added $prefix, $suffix and $first_url properties to Pagination library.
    • Added the ability to suppress first, previous, next, last, and page links by setting their values to FALSE in the Pagination library.
    • Added Security library, which now contains the xss_clean function, filename_security function and other security related functions.
    • Added CSRF (Cross-site Reference Forgery) protection to the Security library.
    • Added $parse_exec_vars property to Output library.
    • Added ability to enable / disable individual sections of the Profiler
    • Added a wildcard option $config['allowed_types'] = '*' to the File Uploading Class.
    • Added an ‘object’ config variable to the XML-RPC Server library so that one can specify the object to look for requested methods, instead of assuming it is in the $CI superobject.
    • Added “is_object” into the list of unit tests capable of being run.
    • Table library will generate an empty cell with a blank string, or NULL value.
    • Added ability to set tag attributes for individual cells in the Table library
    • Added a parse_string() method to the Parser Class.
    • Added HTTP headers and Config information to the Profiler output.
    • Added Chrome and Flock to the list of detectable browsers by browser() in the User Agent Class.
    • The Unit Test Class now has an optional “notes” field available to it, and allows for discrete display of test result items using $this->unit->set_test_items().
    • Added a $xss_clean class variable to the XMLRPC library, enabling control over the use of the Security library’s xss_clean() method.
    • Added a download() method to the FTP library
    • Changed do_xss_clean() to return FALSE if the uploaded file fails XSS checks.
    • Added stripslashes() and trim()ing of double quotes from $_FILES type value to standardize input in Upload library.
    • Added a second parameter (boolean) to $this->zip->read_dir('/path/to/directory', FALSE) to remove the preceding trail of empty folders when creating a Zip archive. This example would contain a zip with “directory” and all of its contents.
    • Added ability in the Image Library to handle PNG transparency for resize operations when using the GD lib.
    • Modified the Session class to prevent use if no encryption key is set in the config file.
    • Added a new config item to the Session class sess_expire_on_close to allow sessions to auto-expire when the browser window is closed.
    • Improved performance of the Encryption library on servers where Mcrypt is available.
    • Changed the default encryption mode in the Encryption library to CBC.
    • Added an encode_from_legacy() method to provide a way to transition encrypted data from CodeIgniter 1.x to CodeIgniter 2.x. Please see the upgrade instructions for details.
  • Database
    • Added swap_pre value to database configuration.
    • Added autoinit value to database configuration.
    • Added stricton value to database configuration.
    • Added database_exists() to the Database Utilities Class.
    • Semantic change to db->version() function to allow a list of exceptions for databases with functions to return version string instead of specially formed SQL queries. Currently this list only includes Oracle and SQLite.
    • Fixed a bug where driver specific table identifier protection could lead to malformed queries in the field_data() functions.
    • Fixed a bug where an undefined class variable was referenced in database drivers.
    • Modified the database errors to show the filename and line number of the problematic query.
    • Removed the following deprecated functions: orwhere, orlike, groupby, orhaving, orderby, getwhere.
    • Removed deprecated _drop_database() and _create_database() functions from the db utility drivers.
  • Helpers
    • Added convert_accented_characters() function to text helper.
    • Added accept-charset to the list of inserted attributes of form_open() in the Form Helper.
    • Deprecated the dohash() function in favour of do_hash() for naming consistency.
    • Non-backwards compatible change made to get_dir_file_info() in the File Helper. No longer recurses by default so as to encourage responsible use (this function can cause server performance issues when used without caution).
    • Modified the second parameter of directory_map() in the Directory Helper to accept an integer to specify recursion depth.
    • Modified delete_files() in the File Helper to return FALSE on failure.
    • Added an optional second parameter to byte_format() in the Number Helper to allow for decimal precision.
    • Added alpha, and sha1 string types to random_string() in the String Helper.
    • Modified prep_url() so as to not prepend http:// if the supplied string already has a scheme.
    • Modified get_file_info in the file helper, changing filectime() to filemtime() for dates.
    • Modified smiley_js() to add optional third parameter to return only the javascript with no script tags.
    • The img() function of the HTML helper will now generate an empty string as an alt attribute if one is not provided.
    • If CSRF is enabled in the application config file, form_open() will automatically insert it as a hidden field.
    • Added sanitize_filename() into the Security helper.
    • Added ellipsize() to the Text Helper
    • Added elements() to the Array Helper
  • Other Changes
    • Added an optional second parameter to show_404() to disable logging.
    • Updated loader to automatically apply the sub-class prefix as an option when loading classes. Class names can be prefixed with the standard “CI_” or the same prefix as the subclass prefix, or no prefix at all.
    • Increased randomness with is_really_writable() to avoid file collisions when hundreds or thousands of requests occur at once.
    • Switched some DIR_WRITE_MODE constant uses to FILE_WRITE_MODE where files and not directories are being operated on.
    • get_mime_by_extension() is now case insensitive.
    • Added “default” to the list Reserved Names.
    • Added ‘application/x-msdownload’ for .exe files and ”application/x-gzip-compressed’ for .tgz files to config/mimes.php.
    • Updated the output library to no longer compress output or send content-length headers if the server runs with zlib.output_compression enabled.
    • Eliminated a call to is_really_writable() on each request unless it is really needed (Output caching)
    • Documented append_output() in the Output Class.
    • Documented a second argument in the decode() function for the Encryption Class.
    • Documented db->close().
    • Moved _remove_invisible_characters() function from the Security Library to common functions.

You can grab complete list of changes with bug-fixes here. Though considering a major release I do not see any changes gives developer Wow…! experience..! majority were expected changes or enhancements over time.

It’s not officially released yet but when we download it has User Guide ready and we may see few more changes before it gets officially available for production. But I am sure one can use it for production (if had hands with CI previously or been PHP expert to take care if something goes unexpected.)

So did you got your hands on CodeIgniter2? How was your experience with CI so far?