[eluser]Mark Skilbeck[/eluser]
Cheers for the info, everyone.
[quote author="slowgary" date="1238276463"]There's nothing programmatic that would stop you from doing so but no, it isn't in the true spirit of MVC. They probably should call it MCV, because the M and the V shouldn't touch eachother
It's not going to kill anything if you needed to do it that way. Remember: this framework, as well as MVC principles, are only here to make things easier. If you need to break the rules to make things easier than just do it. The downside is, in the long run it will probably make things harder when you need to alter your app, but your view relies specifically on your model.
You can always retrieve the output of a view if you need to do further processing, like so:
Code:
$markup = $this->load->view('my_view', $data, true); //3rd parameter returns view to you
Then your controller can do additional processing.
What is it you're trying to do? Maybe someone can recommend a better alternative for you than accessing the model from the view.[/quote]
Ok, gary. Here's the scoop. In my database I have the tables 'projects' and 'project_changelogs'. I want to display, in a view, the projects and their changelogs in list view.
Code:
- project 1
- project 1, changelog 1
- project 1, changelog 2
I have a couple of methods in a model that I can use to handle the retrieval of all changelogs and all projects, and I use them in the controller to pass all this data to the view.
Code:
$vars['projects'] = $this->db->get_all_projects( );
$vars['projects_changelogs'] = $this->db->get_all_changelogs( );
However, I soon realised that my view would get congested with more PHP logic than I'd like to use - having to loop through each array, grabbing the relevant data from each, as compared to if I could just call the model from my view, passing the project name (retrieved from $projects->result)) for use as a WHERE clause.
Does that make sense, or am I going about this the wrong way?
Cheers, everyone.
- Mark.