Welcome Guest, Not a member yet? Register   Sign In
How should I design the my user library?
#1

[eluser]Unknown[/eluser]
I have a question about models.
I want to create a user and a session library. These Libraries should be so dynamic that I can use them again for other projects. This is not my problem. My problem is to design this library with the MVC concept.

I have three solutions but I don’t know which the best is:
1. I create the user and the session library and I write all database stuff in these libraries, too.
2. I create the user and the session library and create also a model (user_model and session_model) which has all functions like addUser and deleteUser which does the entire database stuff. The user library has an addUser function too but these function call the addUser function of the user_model which does the entire database stuff for this function.
3. The user library is just a model which also has all the function. With all functions I mean the functions where I don’t do anything with the database.


Which is the best practise? Has someone an example for me? I want to work with the solution which is the most professional solution.
Thanks for help ;-)

Tim
(Sorry for my bad english :-( )
#2

[eluser]PhilTem[/eluser]
Version 2 is like best practice. You use the library to "combine" the functionality of two or more models and add other methods on top which then do more advanced stuff easier than you would be able to by just combining the two models in a controller.

In addition, version 2 is, in my eyes, the most professional solution since you're still able to extend the library and use a third, forth, ... model within the lib. Just add the appropriate models and it's done.

Of course you can still use the models directly, but it'd be more convenient to just use the library from the time writing on.

I don't have a really good example at hand but you might wanna have a look at an older version of my auth-library which combines the user-model as well as the remembercodes-model.
#3

[eluser]Unknown[/eluser]
Thanks for your help.
I will try it. I think your example is really good to see how I can design such a library.


Thank you ;-)
#4

[eluser]Unknown[/eluser]
I did a small auth library that uses three files.

* Config file -- Some stuff like hash key, hash type, identity columns and tables
* Model file -- Handling all data stuff and create a session called user.
* Library file -- Call the model file and handles logic, redirects and other stuff.


In my controller I load the Auth library file and simply call $this->auth->login() or any other method you have put in the Auth library.


I try to keep the code as generic as possible.




Theme © iAndrew 2016 - Forum software by © MyBB