• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Starting with CodeIgniter setup: suggestions & best practices

#24
[eluser]Jelmer[/eluser]
The statement you referred to is of course a simplification of how things work. In essense you'll need logic everywhere in your application, even in your views. It's indeed the function specific logic that's not to be reused in other function that should be in the Controller, the other kinds of logic should be in libraries/models/helpers.

While I agree with most of what you said I have some notes:
Quote:If it’s output, it should be in a view. However, you should try to keep as much logic as possible OUT of the views and instead put it in a helper (or if the formatting logic is more complex and deserves a class, continue down this list).
Yes and no. While you shouldn't have any data-access and such in the view, you might need some post-processing of your data specific to your layout - that kind of logic should be in the view in my opinion. And helpers should only be involved when the functionality is needed in more then the one view, creating functions for just one view is just clutter and would be better within the view it is used in.

Quote:- If it’s logic that could potentially be used in multiple applications (api access, generic classes), it should be a library.
- If it’s logic that is application specific (some call this business logic) and it could potentially be used more than once in your application, it should be in a model.
This part of your list I don't get: models are for data-access and pretty much data-access only. Libraries are for functionality/logic to be shared among controllers, and if that involves data-access as well then you need both a library and a model for the "right" solution.
But functionality to be shared among applications? That's also something where libraries are good for, but not native CI functionality and probably not good for a generic list for beginners. How do you load libraries in multiple applications? Do you put that in the system/libraries folder? Or have you written an extention of the load->library() function? (the second being the preferable solution)

About the error reporting solution: That's more of a suggestion then a best practice, it's just how I like to do it but I can imagine there are many other ways.


Messages In This Thread
Starting with CodeIgniter setup: suggestions & best practices - by El Forum - 04-19-2010, 09:24 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.