Just a few generalized questions |
[eluser]kaos78414[/eluser]
In an effort to better understand MVC structure, I have a few general questions. Firstly, what is the difference between helper and library classes? For instance: If I have a function or two that is used globally, should that be contained in a library? Secondly, I have a certain code that checks session data for ACL related information. Should I put the if statement to return certain data in my view file, or in a function in a controller class ? For instance, in the view I could have: Code: <?php if ($this->session->userdata('access_lvl') == 1) : ?> Or should I have the controller call different view files for different cases like so: Code: function check_access_level() { Essentially both do the same thing right? So is there a reason I should be using one or the other? Or are both okay?
[eluser]WanWizard[/eluser]
A helper contains functions, a library contains methods. The only difference is the way you call them (next to some other benefits of working with an object, like private methods and class variables). I use helpers the same way CI does: for simple and more or less stand-alone functions. For functionality that requires multiple functions to implement, I use a library. In an MVC environment, your view generates your output. It doesn't contain business logic. The idea is that you put that in your models, and use the Controller to 'glue' the models to the views. I would go for your second option, if only because it would create much more maintainable views.
[eluser]kaos78414[/eluser]
Do you think you could give an example of a scenario where you would use a helper and one where you would use a library? It would help me out a lot to see an example ![]() Also, how do you usually organize your view files? Is it normal to have lots of sub-folders? I'm sorry if these are novice questions ![]() I'm still in the learning process
[eluser]WanWizard[/eluser]
As a bit of code says more than a thousand words: Check for yourself... Our project doesn't use views, we use a template engine (Smarty in this case) because of separation requirements.
[eluser]kaos78414[/eluser]
Oh nice! That'll be a good resource for me. Thanks!
|
Welcome Guest, Not a member yet? Register Sign In |