Avoid using other libraries in own library |
Heya guys!
I have another (probably stupid - I apologize in advance) question. After getting a lot of advice in one of my previous threads, I figured that I'd like to move most of my controllers' functionality into libraries. Also, in order to keep those libraries as independent as possible, I am trying to avoid using other libraries in my own. To be even more specific: Right now, I'm implementing a basic user system as a library. For the reason above and also because I would like to keep my login (And other functionality) functional even if no HTML form is provided, I do not want to use libraries such as CI's form validator in my library's code. Basically, the code in the library should only give basic functionality that runs depending on a certain input. The input shouldn't be read-out by itself, but rather by the code in the controllers, or some other place. I hope I'm making sense, but if I'm not, here's the code I currently have - Followed by a small description of my actual problem. (I hope that I created this thread in the right sub-forum, but it looks like a "Best practice" problem to me, since I could easily solve it by removing the barriers I put up myself - Obviously, I do not want to do that, though.) In my library: PHP Code: To clarify: "cUser" is a CI Model used to perform queries to the database. In my controller (Old function, not adapted to the use of my library. My following question will be about how to best adapt it.): PHP Code: function login($lastURL = "/user/"){ //set default to view user (todo) PHP Code: //My library is loaded in the contructor or something. 1) I can't check if the user is already logged in. Because if he is, the login page will get displayed anyway. Running my library's function before the form validation would also be bullshit though, since I don't have anything I can pass as argument. 2) Even though I wanted to be library independent, I'm still using the session library in my own library. This is a minor problem, but if someone has an idea on how to beautifully avoid this, I'd be glad to hear it! 3) Nah, actually the main problem is the first. I do not want to call my library's function twice, but I don't see another solution that wouldn't completely butcher the code. Does anyone have an idea ? Thanks! |
Messages In This Thread |
Avoid using other libraries in own library - by Call-Me-Captain - 08-03-2016, 10:57 AM
RE: Avoid using other libraries in own library - by cartalot - 08-03-2016, 05:17 PM
RE: Avoid using other libraries in own library - by Call-Me-Captain - 08-04-2016, 04:19 AM
RE: Avoid using other libraries in own library - by PaulD - 08-04-2016, 05:20 AM
RE: Avoid using other libraries in own library - by Call-Me-Captain - 08-04-2016, 05:38 AM
RE: Avoid using other libraries in own library - by ivantcholakov - 08-04-2016, 05:53 AM
RE: Avoid using other libraries in own library - by PaulD - 08-04-2016, 06:06 AM
RE: Avoid using other libraries in own library - by mwhitney - 08-04-2016, 06:38 AM
RE: Avoid using other libraries in own library - by Call-Me-Captain - 08-06-2016, 02:03 PM
|