Welcome Guest, Not a member yet? Register   Sign In
advice on best practices in CI 2.x re: Libraries, Models, Helpers, and OOP overall
#1

[eluser]Chillahan[/eluser]
I am starting a massive new project and would like to use CI 2 (instead of 1.6). However, beyond changing some of the basics to PHP 5 syntax, is there anything really different about how I should go about it? (I know the deprecated parts, but in terms of using OOP.)

For example, this project will require a representation of a somewhat complex project that will change over time. Different parties will submit data to the project. The project will have different stages, and at some point will have reports that are able to be run. Also, there will be different viewing permissions based on stage, and changing stage (like new to development to testing to finished) will require certain requirements from each user to be in place.

In the past I would have put a lot of the logic in the controller and in the model. Does the use of a Library help me in any way? For example, is an instantiation of a custom Library stateful, so that I would not need to be loading the same data all the time? And would that be a good place to put business code that is not really best in the controller and a bit more logical than a CRUD operation in the model layer?
#2

[eluser]mdvaldosta[/eluser]
Use libraries for code (classes) that multiple controllers/models need to share. For example, user authentication. If you just need a quick function available in multiple places, stick that in a helper.
#3

[eluser]Chillahan[/eluser]
Right, but what if I have something more complicated, like changing the status of a project but first checking that all stakeholders have signed off on the draft and that certain project specs are in place, etc. - it's all really only going to happen in one controller for changing the status, so I guess it just continues to live in the controller (and/or the model that does this status update - this is how I do such things to date)? Or if I really want to make it look "clean", I could put it in a Library anyway?

I am thinking it would make sense, because then I could have multiple private functions in the class, and check different things among those functions. Even though I access the main function only from one controller, it would help keep the controller leaner and split the code up more in the library. DOes this sound like the right approach?

I already have plans to put user permissions in a Library, since there are several levels, and they change based on which controller is being accessed, the status of the project, the seniority of the user, etc.




Theme © iAndrew 2016 - Forum software by © MyBB