views:

21

answers:

1

Im currently using codeigniter to build a messaging system and im trying to stay within the MVC guidelines, however I can't seem to find a way to easily update dynamic page content without having the HTML dynamically generated in the controller; which I believe is frowned upon when using an MVC framework.

Currently I am using ajax to refresh the content of a frame by using what is basically a "view" stored in the controller. This chunk of html is generated dynamically and then passed along to the ajax.

Im looking get around this because although it does work, it seems sloppy.

A: 

Sure there is. Send a request off to your controller and let the controller load the view as a string. Something like:

$this->load->view('myview', $dataArray, true);

This last parameter is set to false by default, but if you set it to true, it simply returns a string of HTML that is the output of your view. In fact, I find this method to be extremely easy because it means I really get to keep all my HTML in one place. I don't even need to have any in my javascript.

treeface
Thanks alot that seems like it's exactly what i was looking for