Emran Hasan

Code Updates (HTTP class, Extended CodeIgniter Model, Cross-domain AJAX transport)

Feb 18, 2009

Greetings to all the readers of my blog.

Many of you have been writing to me in the last couple days when I took the site down. The main objective was to add the new theme and push a few code updates of the existing libraries. I really appreciate your concern and would like to reassure you that the site is up and will be up as usual :) Now, besides the slightly customized theme from Elegant Themes, I have put a few code updates. They are detailed below:

Extended Model for CodeIgniter

The original version of the Extended Model for CodeIgniter has been serving many people well. Although most users loved the nifty functions of the Model, many (including me) didn’t like the hacking of CI core to get this functionality. With the release of CodeIgniter 1.7, we can avoid that as we can now overload the Model class of CI like the other libraries. Follow this instruction:

1. Download the updated version from here
2. Put it in your application/libraries folder
3. In your model files, use it this way: class Product extends MY_Model
4. Everything else is same just like the original one

HTTP Class

There is not much update in this class except for a few bug fixes (thanks to you guys). Also, I have included a license file in the package as many of you have asked. It’s released under the MIT license. The original post is here for reference.

Download the update from here and the API reference is here.

Cross-domain AJAX calls using PHP

A minor bug fix in the code. Thanks to a few of you who pointed them out. Original post is here. Download the update from here.

I have accelerated plans for the blog in 2009 so stay tuned for some worthy posts in this month. And do write to me if you feel you have any questions/ideas/suggestions.

Cheers!

There are 14 comments in this article:

  1. 18/02/2009Extended Model for CodeIgniter | Md Emran Hasan (phpfour) says:

    [...] Extended Model for CodeIgniter Posted by admin in Code Igniter, PHP, Programming, RBS on 07 12th, 2008 | View commentsComments There is an update to the code for CodeIgniter 1.7.xhere. [...]

  2. 19/02/2009Ryan Blunden says:

    Hi Emran,

    Many thanks for these excellent classes!

    I've used the Extended Model class in a recent project and it saved me so much time in not having to create the simple Models just to do basic insert, save, findAll etc. Great work!

  3. 25/02/2009g says:

    very good

  4. 27/02/2009starrynighthn says:

    I've found 1 bug in MY_Model:

    When I use $returnArray = FALSE, findCount() got error. So I changed this code:

    $data = $this->findAll($conditions, 'COUNT(*) AS count', null, 0, 1);

    if ($data)
    {
    return $data[0]['count'];
    }

    to this:

    $data = $this->findAll($conditions, 'COUNT(*) AS count', null, 0, 1);

    if ($data)
    {//fixed by starrynighthn
    if ($this->returnArray)
    return $data[0]['count'];
    else
    return $data[0]->count;
    }

    and everything works well.
    Hope you fix this bug. ;)

  5. 28/02/2009Mike says:

    Emran, thanks for making this available.

    I was wondering if you could post some sample code showing how you generally use the extended model, specifically when creating a new record.

    Thanks.

  6. 9/03/2009$@!ful says:

    Nice job…

  7. 23/05/2009North2Alaska says:

    On line 123 of the My_Models.php file, shouldn't the constructor by My_Model instead of just Model?

  8. 21/09/2009Ron says:

    Hi Emran,

    Great job on this! I was testing it out and it worked perfectly.

    One thing though–is it possible to join tables with this? For example, if you have two tables such as 'products' and another called 'images', where product image names are stored in the images table. How would you do the combine and throw in a condition?

  9. 21/09/2009Md Emran Hasan (phpfour) says:

    Hi Ron,

    At this moment JOIN is not supported within this class. The purpose of this
    class is to assist with most regular DB operation, not the complex ones. I
    believe when using JOIN, the query should be hand-written with proper
    ordering etc.

    Glad this is helping you!

    Emran

  10. 22/07/2010Prevolution says:

    Thanks for this library! It helped me very much :-)
    There was problems with cookie transfer, but I replaced this line:

    $cookieString = join('&', $tempString);

    with this:

    $cookieString = join('; ', $tempString);

    and it worked for me.

  11. 8/09/2010Jonathan says:

    North2Alaska

    On line 123 it is correct the way it is with Model. The class itself is already extended with MY_Model extends Model therefore the function Model() within the MY_Model class in MY_Model.php is replacing the function Model() in the original Model.php, and since there is no MY_Model function in the original Model.php, if you changed line 123 to “function MY_Model()” the the Model() function would not be overridden, but instead it would use the original Model() function from Model.php which defeats the purpose of having a class override.

  12. 9/12/2011Custom CodeIgniter Model Class | Zach Flower says:

    [...] December 8, 2011 | PHP | 0 Comments For the past year, I have been an adamant CodeIgniter developer. The one thing that I have found lacking, however, is CodeIgniter’s model class. I am a big fan of the simplicity of CakePHP’s ORM structure, and wrote this model class to (slightly) mimic it. Some of the functionality in this extended model is inspired by Emran Hasan’s CodeIgniter Extended Model Class. [...]

  13. 16/01/2012Mikkel says:

    The download link for transport.php seems to have disappeared, and all links just lead back to the same page.

  14. 24/03/2012Emran Hasan says:

    There are better solutions for this problem, for example JSONP. Consider using them as this is pretty old technique. Thanks for your interest though.

Write a comment: