Welcome Guest, Not a member yet? Register   Sign In
How a Library Should Work
#1

[eluser]Popcorn[/eluser]
How a Library Should Work

Hi,

This topic was sparked from my quest to get my authentication library to the best standard it could be. I was discussing it in the IRC when pygon suggested I not include the model because the library should not rely on the application to work. Application (Model, View, Controller).

I have moved the code that used to be in the model into a new class within the library and it works quite well.

I just wanted to hear your thoughts on what should and should not be included when distributing a library.

Kind Regards,
-Mathew

[Edit] Just an after thought. There should be a standard which libraries should adhere too to get some standardisation across the board.
#2

[eluser]Majd Taby[/eluser]
It depends on how you want to package it. The MVC design doesn't have a letter for "libraries" as we know them in CI...as such, it's really up to the developer. If I am to release a library that interacts with the database, I would not use a model or rely on the application. The reason is that it makes the installation easier, and it makes the code more centralized. Granted, if the library does a lot, you may consider splitting it up into the parts so you don't have a single 4000 line file.
#3

[eluser]nmweb[/eluser]
As a general rule I have that if I need model stuff in a library, something is wrong with the library and it probably shouldn't be a library at all but a controller in the shape of Modular Extensions controller. This is only a general rule, just means I have to justify it to myself when I break it Smile

The issue you talk about is difficult. Basically comes down to: What place do libraries have in an MVC framework. Imo they should DRY up your code, be quite generic and should serve your controllers. Having them mingle with your application logic is undesirable, if so it's not a library but a module. It can be more elegant to have authentication with models etc. but it then moves away from being a library to being a module. On the other hand, accessing your db in your authentication library and thus bypassing the model is not the most elegant of solutions.

Personally, I'd do the checking of user/pass correctness in the User model. The User model models the user and thus also whether the user is logged in, privliges and any session data.
#4

[eluser]xwero[/eluser]
[quote author="Popcorn" date="1209079777"]I have moved the code that used to be in the model into a new class within the library and it works quite well. [/quote]

Why not make an active model. Move all the authentication code to the model. In my view if a library depends on data to make it work you should make it a model instead of a library.

Models are defined as classes that output and manipulate data. There are a lot of discussions about what a model has to output but i think the active/passive model concept is generally accepted.

I don't want to revive the discussion about the use of libraries and models but it could be an alternative to consider if you are developing your authentication code.

edit : i should have read mnwebs response first. I just responded with the dummy version Smile
#5

[eluser]Popcorn[/eluser]
See, this is exactly what I talked about. Everyone has a different view on how libraries should be implemented, there is no standard to adhere too when creating one. I hope to see this in future versions of CodeIgniter.

To be honest, for now I will put all code into the library file to keep easy for the end users sake.




Theme © iAndrew 2016 - Forum software by © MyBB