Welcome Guest, Not a member yet? Register   Sign In
Newbie needs a bit of help with MVC concepts
#1

[eluser]Unknown[/eluser]
Hello, I am a newbie to programming and wanted to develop a website with PHP. A programmer friend of mine recommended that I develop my site using a framework to make it easier for me and so far I am really loving CI.

I've done lots of reading up on this awesome framework and have already made lots of progress on my website. I am now spending a bit of time "optimizing" the code before I make some really big strides with it.

I love MVC and how it works but I am having trouble with one aspect of this and my code and could not find anything specific enough about how to do this in the forums or my readings. Any help would be greatly appreciated (and paid forward at the first available opportunity).

Here's my predicament:

- I have my model file set up. It is one file that accesses all the tables in my database with individual queries in functions.

- I have many controllers (soon to be dozens of them) that load this model. In each controller I put each query function into an array and then pass all those arrays into the view.

- My views then use these arrays to build the menu for the website.

Now my understanding of MVC is that if you are repeating code across files you are probably doing it wrong and in my outlined system above I have the same chunk of code in every single controller function that outputs model data into arrays and then passes it into my view to create the menu.

Clearly it makes sense that these functions could be "encapsulated" somewhere and be called with one line of code into the controller functions so that if they had to be changed in the future they could be changed in one place instead of having to edit hundreds of files down the road. I just am not sure how to do this being a novice at all this.

I don't think I can put them in a model since they don't really have queries, they are just putting query results into an array.

I don't guess they belong in the controller since I am repeating them over in every controller I make.

Clearly they don't belong in a view.

Any direction that someone could give me on this would be a huge help. It would further my understanding of programming as well as MVC. This alone would also greatly advance my progress with my site. I feel like there might be more of a problem here with the placement of the code, perhaps I am making a mistake with the fundamentals of how I am doing this process.

Thank you so much for your time and help. If you need to see my code I would be happy to post examples of my MVC.




Theme © iAndrew 2016 - Forum software by © MyBB