Welcome Guest, Not a member yet? Register   Sign In
How can I display dynamic contents in a view (not dynamic views)?
#1

[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!
#2

[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
#3

[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
#4

[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
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB