CodeIgniter Forums
Basic design question - where to put the a API connection class - extend the model? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Basic design question - where to put the a API connection class - extend the model? (/thread-34751.html)



Basic design question - where to put the a API connection class - extend the model? - El Forum - 10-08-2010

[eluser]MEM[/eluser]
I have a connection class that needs to be used by several model files. Not all however.

I should call this connection on each model that I need to use it. - I presume.

So, at this moment I'm using something like:
Code:
class myStuff extends Model {

So, one way for doing this could be:

Code:
class myStuff extends MyModel {

and MyModel will extend Model.

By doing so, I can call my connection class on "MyModel";


What do you think?


Regards,
Márcio


Basic design question - where to put the a API connection class - extend the model? - El Forum - 10-08-2010

[eluser]OliverHR[/eluser]
Maybe you can configure two database instances on your config/database.php and then call explicitly a connection group. Even better you can write a funtion doing this on MY_Model, extend this class on your Models and call the function.


Basic design question - where to put the a API connection class - extend the model? - El Forum - 10-08-2010

[eluser]MEM[/eluser]
Yes that last option was what I was talking about. Wink

It works. I used MY_Model the MY_Model extends Model and, on one of MY_Model method I have a database connection class call.

Just wondering if this is a nice way of doing so...

Wink Regards


Basic design question - where to put the a API connection class - extend the model? - El Forum - 10-08-2010

[eluser]bretticus[/eluser]
[quote author="MEM" date="1286571670"]Yes that last option was what I was talking about. Wink

It works. I used MY_Model the MY_Model extends Model and, on one of MY_Model method I have a database connection class call.

Just wondering if this is a nice way of doing so...

Wink Regards[/quote]

That's actually a good way to go about it. I would have probably put it in the constructor for each Model where I needed it, but that's not very DRY.


Basic design question - where to put the a API connection class - extend the model? - El Forum - 10-08-2010

[eluser]MEM[/eluser]
[quote author="bretticus" date="1286572710"]
That's actually a good way to go about it. I would have probably put it in the constructor for each Model where I needed it, but that's not very DRY.[/quote]

True. I found that I'm starting to understand, finally, the balance of this.
Better saying the economy around those decisions.

It seems that we can never be totally DRY on the process.
At some point we have to do it. On the other hand however, we can well think about abstraction and abstraction of abstraction, in order to build our systems...


Anyway, thanks a lot for your feedback. Wink More confident for the next issue.


ps- I still remember the day when someone said to me: "Extend the Controller class by creating your own" and I thought... no way. That's to complicated. Wink