PHPFour’s Extended CodeIgniter Model

PHPFour has just posted an excellent extended model for CodeIgniter. It is definitely an impressive piece of code and I have already included it within my local application repository (meaning, it’s going to become an active part of all my future CodeIgniter applications).

I had been working on my own ORM solution but I think PHPFour’s library has a much better approach - it feels more like CodeIgniter to me than my own solution. I’ve yet to dig through the code extensively but upon first glance I didn’t notice any relationship methods which would definitely be a worthy addition to this library.

Finally, I’d like to offer an errata to their installation instructions:

1. Replace the system/libraries/Model.php file with the attached Model.php (CodeIgniter version 1.6.3)

Should be:

1. Rename the attached Model.php to MY_Model.php and place within your application/libraries directory.

We all know you shouldn’t be hacking the core…

5 Responses to “PHPFour’s Extended CodeIgniter Model”

  • Alex

    Actually the instruction should be
    1. Replace the application/libraries/Model.php file with the attached Model.php (CodeIgniter version 1.6.3)

    If you were to save the model as the file MY_Model, then the default CI model class will be loaded as well, causing a name conflict.

    You’d also need to make sure that all your models extend MY_Model, and not Model (and you should also make sure you rename the constructor too).

    It looks like an interesting concept, however I prefer the traditional codeigniter models, partly because it means that if I change a field name I don’t have to change all calls to the model. I also have better control over caching the results.

  • Alex

    I mean, place the model file in the app/libraries, not replace :P

  • As PHPFour’s model is not an extension but a replacement, here’s how I would set it up.

    Open PHPFour’s ‘Model.php’ and do the following to it:

    Change:

    class Model {

    To:

    class CI_Model {

    Change:

    function Model()

    To:

    function CI_Model()

    Save the file as ‘Model.php’ and place it in:

    application/libraries

    This is the proper way to replace core libraries. Source:
    http://codeigniter.com/user_guide/general/core_classes.html

  • Although after testing, that doesn’t work o.O

    Leaving out the CI_ and putting it in application/libraries allows it to run perfectly fine.

    I wonder why CodeIgniter doesn’t allow the CI_ override for the Model?

  • MCoffey

    Stensi

    Can’t get this to work at all within application/libraries but in my many trials I did discoverwhy CI_Model doesn’t work - unlike CI_router and CI_Loader the base class name is just ‘Model’ not CI_Model.

    Looks good though. If I crack it (without replacing the core) I’ll let you know

Trackbacks

  •