-
Website
http://www.phpfour.com/blog -
Original page
http://www.phpfour.com/blog/2008/07/extended-model-for-codeigniter/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
robskils
1 comment · 1 points
-
joshsharp
1 comment · 1 points
-
nirjhar
1 comment · 1 points
-
Nhm Tanveer Hossain Khan
1 comment · 1 points
-
cubanhenry5
1 comment · 1 points
-
-
Popular Threads
You've saved CodeIgniter developers valuable time. :D
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.
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.
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.
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.
@mariano - Damn dude. Relax. He did thank CakePHP for their inspiration. NO need to be so anal.
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.
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_...
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?
Go away you miserable creature. Take your nastiness to a cake forum.
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.
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.
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.
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!
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 :)
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!
Everybody, please follow Jacob's two comments if you're using CodeIgniter 1.7.0.
Cheers!
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.