CodeIgniter Forums
How can I display dynamic contents in a view (not dynamic views)? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How can I display dynamic contents in a view (not dynamic views)? (/showthread.php?tid=31279)



How can I display dynamic contents in a view (not dynamic views)? - El Forum - 06-12-2010

[eluser]excelln[/eluser]
Hi all,

I have been playing CI for a while. Recently I was stuck on a problem that is how can I put dynamic contents in a view? My application will read some thousands records from a db; each record will be processed and will be displayed on the view as a single line so user knows the progress. I have a loop in my controller to process those records. But how can I load view so user knows the progress? If I load the view in the loop in the controller, the view will be totally messed up. If I load the view at the end of the controller, the view will be only shown the last record. Unfortunately, I couldn’t find a similar thread on the forums searching. How can I display dynamic contents in a view? Any idea, thank you!


How can I display dynamic contents in a view (not dynamic views)? - El Forum - 06-12-2010

[eluser]siubie[/eluser]
maybe using ajax to load the content dynamic stuff.

put a div in the view then load the div periodicly using jquery or another ajax javascript frameworks


How can I display dynamic contents in a view (not dynamic views)? - El Forum - 06-13-2010

[eluser]pickupman[/eluser]
You can have view return their html. This is used quite a bit once your application grows, and you'll find the use for partial views. Use:
Code:
//Render html and save to string
$data['content'] = $this->load->view('dynamic_content',$data,TRUE);

By passing TRUE as the third parameter, you get the html contents returned rather than be sent to the browser. You can than process as many blocks/views as you need to and then send to a master/display view.

Code:
$data['content'] = $this->load->view('dynamic_content', $data, TRUE);

//Set a new record to be rendered and save it
$data['content'] .= $this->load->view('dynamic_content', $data, TRUE);

//Rinse and repeat as necessary

$this->load->view('page', $data); //Let's see the whole thing now



How can I display dynamic contents in a view (not dynamic views)? - El Forum - 06-13-2010

[eluser]Razvan Juravle[/eluser]
[quote author="siubie" date="1276425651"]maybe using ajax to load the content dynamic stuff.

put a div in the view then load the div periodicly using jquery or another ajax javascript frameworks[/quote]

totally agree, and eventually i think from experience that is a very simple and elegant solution Wink


How can I display dynamic contents in a view (not dynamic views)? - El Forum - 06-13-2010

[eluser]excelln[/eluser]
thank you, siubie, pickupman and Razvan Juravle. I am going to try jquery.