DISQUS

Md Emran Hasan (phpfour): Extended Model for CodeIgniter | Md Emran Hasan (phpfour)

  • Anis uddin Ahmad · 1 year ago
    Thanks a lot man.
    You've saved CodeIgniter developers valuable time. :D
  • Mariano Iglesias · 1 year ago
    In the world where I live, when you take off the code that someone else built, or steal its ideas, it's nice to give a credit back. And if you DID take out the source code, you need to abide by their license agreement.

    On this particular case your source code (mainly its method names and implementation) look strangely familiar to CakePHP's model implementation (for outsiders, concentrate on the method names and signatures):

    https://trac.cakephp.org/browser/branches/1.2.x...

    To give a small preview of the similarities:

    * $this->data and $this->useDbConfig used on both
    * getAffectedRows()
    * getNumRows()
    * getInsertID()
    * getID()
    * lastQuery()
    * query()
    * remove()

    Well, almost all methods are borrowed from CakePHP implementation.

    So I think you seriously need to revisit your use of open source software and inability to respect its MIT license.
  • joeri.cochuyt · 1 year ago
    tnx, very handy indeed.
  • walesmd · 1 year ago
    I recommend making the following change to your installation instructions:
    1. Rename the attached Model.php to MY_Model.php and place within your application/libraries directory.


    You should never hack the core - it makes upgrading a pain.

    Thanks for the great library - I posted a link to this from my blog as well as some of my own comments concerning it! A great contribution to the community.
  • Emran Hasan · 1 year ago
    @Wales,

    Thanks for the appreciation. I actually tried not to hack into the core but the overloading of base CI classes didn't work with the Model class.

    If you can get it working in any way, I'd be more than happy to follow that and update the install steps accordingly.

    Thanks a lot.
  • Emran Hasan · 1 year ago
    @Mariano

    Thank you very much for reminding me the source. It is my bad that I completely forgot to mention the credit to CakePHP's model implementation.

    I actually created this in the middle of last year and have been using from then. The day I posted it here, I was actually rushing - so the due credit was missing. I'm going to update the post with a mention to this.

    And btw, I've only taken inspiration for the methods and variable names. The code utilizes the Active Record library of CodeIgniter. Also, it doesn't burden the developer with the associations.

    Thanks a lot.
  • pengekcs · 1 year ago
    Nice one there. Thanks for posting it. Small, but nice addition to CI. ;)
  • taewoo · 1 year ago
    Good one.

    @mariano - Damn dude. Relax. He did thank CakePHP for their inspiration. NO need to be so anal.
  • Mariano Iglesias · 1 year ago
    @taewoo: before you post, READ. That works on every level. He DID say he FORGOT to credit CakePHP until I reminded him, so you should double read the comments before you call me anal.
  • Storyteller · 1 year ago
    @Emran

    Great work, Thats what I am saying since you've showed me the code last year sometime. But unfortunately I have left using CI.

    @Mariano
    Thanks for pointing out that method names were borrowed from CakePHP, but that clearly didnt disrespect MIT license model. It is not a derived work but written from scratch, did you note that? I appreciate your observation but I still think you were a bit rough at this one. Anyway, thanks. No hard feelings.
  • stensi · 1 year ago
    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_...
  • stensi · 1 year ago
    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?
  • Ryan · 1 year ago
    @Mariano Douchebag Boy

    Go away you miserable creature. Take your nastiness to a cake forum.
  • Mariano Iglesias · 1 year ago
    Having been (and currently beeing) on several open source projects I know this is not unheard of. But people like Ryan on his comment above (showing that his brain consists only of derogative terms) certainly do not help the projects.

    For the sake of CI, I hope you have more of the "other kind" of people. You know, people that KNOW something about something, and HELP the project back, for a change.
  • Emran Hasan · 1 year ago
    @Ryan: I fully agree with Mariano and would misjudge the CI community in the same way, seeing your response.

    What Mariano did was just to remind me something that I forgot, although in a bit rough way, but he had no bad intention in mind and I thanked him for that.

    We're all community enthusiastic, let's not create divisions and point fingers.
  • joshdavey · 1 year ago
    @Mariano Iglesias

    You really want him to re-name "query(), "getNumRows()", "$this->data" and other method/property names? These are standard method names used by pretty much every database abstraction layer in the history of programming.

    Saying phpfour isn't respecting the MIT license is a bit harsh. He's just looking at other libraries for inspiration and building his own. Nothing wrong with that.
  • Mariano Iglesias · 1 year ago
    @joshdavey: why do a lot of people INSIST ON NOT READING before posting? Check the previous messages, this was SOLVED long ago.
  • haran · 1 year ago
    Great work. It saves us a lot of time.
  • Jacob · 1 year ago
    I'd like to try using this, and I've tried it using Michael's suggestion, eg renaming to MY_Model etc, but I keep getting this error:


    Fatal error: Call to undefined method CI_DB_mysql_driver::field_names() in C:homecodeignitersystemapplicationlibrariesMY_Model.php on line 196



    and I just can't work out how to get around it... any help would be great!
  • Md Emran Hasan (phpfour) · 1 year ago
    Michael's suggestion actually doesn't work, as I mentioned in my reply to him. You'll have to replace the actual Model.php in system/libraries to make it work. Hope this helps.
  • Jacob · 1 year ago
    Well, as always after posting a 'help me!' question, I've worked it out.


    Replace Line 196 of MY_Model.php:



    $this->fields = $this->db->field_names($table);



    with



    $this->fields = $this->db->list_fields($table);



    as field_names() is deprecated, and clearly in 1.7.0 does not work!!



    Hope this helps someone else :)
  • Jacob · 1 year ago
    Thanks for the reply, Emran! I hadn't seen your reply when I posted my fix below.


    What I've done (in addition to the fix below) is rename it to MY_Model.php, placed it in system/application/libraries, updated the constructor to class MY_Model extends Model, and that's literally it. It's all working so far - I'll post back if I hit another snag :)



    It may well be something they've fixed in these latest updates to CI, so you may wish to try it again, and if it works for, update your instructions accordingly.



    Thanks for your contribution - it looks like it will be very useful!
  • Md Emran Hasan (phpfour) · 1 year ago
    Thanks Jacob for pointing this out !!! I've been waiting for long to have CI support this. I will write a separate post with the update and a few additional features I planned long ago (probably post date: first week of Nov).


    Everybody, please follow Jacob's two comments if you're using CodeIgniter 1.7.0.



    Cheers!
  • Abe · 12 months ago
    Forgive the personality analysis, but your seemingly irate attitude towards the author necessitated commentary.


    Do bear in mind that you're a guest on this website, not an unpaid asshole.



    Your message is true, but your delivery is definitely flawed. I'd recommend trying to be a little more polite, or you'll keep getting comments from people like Ryan. While I agree with what you said, the way you came across was pretty overwhelmingly full of douchebaggery. I have not personally visited the CakePHP forums but if they're full of people such as yourself who display a genuine "inability" to be polite, I don't plan on visiting anytime soon.



    It is rather apparent that you're a CakePHP fan, but don't turn it into some form of irrational zeal. Step one would be to resist all caps. Step two would be to assume that other people aren't as brilliant as you, and don't have the MIT license memorised. Step three would be to perhaps quietly suggest that the author credit the source that shows definite similarity to his code snippets, instead of full-force attacking him.



    Thanks for the info, Emran. I was trying to extend Model.php, and I eventually just popped a customised copy of "Model.php" in my APPPATH/libraries folder and overrode the default Model file altogether.