I start with CodeIgniter, still struggling to figure out how best to use the MVC ideology.
I am writing a basic CMS system with the ability to vote on posts and keep track of people, etc., so I found that I use the same or similar code fragments in several views here and there, consisting of different parts of html and logic, for example:
- Voting panel
- Follow / Unfollow Panel
- Entry / Exit Panel
- Code to check if the user is registered, etc.
I am wondering where to put this code so that it can be unified? I think helper is the way to go? If I declare an assistant in the controller, can it be called from the corresponding view?
Some elements are dynamic - for example, the follow / unfollow button - you will need to check if you are already following the user or not, and display the corresponding button for which you need to check the model. Now I have that all the logic is in the controller, and it returns the corresponding button, but it seems strange to return the generated html code in the controller return. If it will be more like:
- Controller
- checks if you are following someone.
- the controller passes the logical view to the view
- the view calls a helper with this value to draw the corresponding button
Also, as a minor issue, I was doing a fair bit of the loop through mysql arrays in foreach loops to handle the mysql results returned from the view. It seems that my views are somewhat complicated, but I can not come up with another way to do this, although perhaps this should be done in another assistant?
Sorry, if this is a naive or recurring question, there really are a lot of discussions on this issue, but it is not always easy to relate to another project.
waffl source share