• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to load specific view part?

i have a view file named index. where i call to load different view files such as header, footer, left content, middle content, right content. from controller i send an array named $result['body'], which is the middle content in the view.
now i want to refresh only the middle content rather than the all view files in the index. is it possible in codeigniter?

below is my index file code.
<?php $this->load->view('gw/gw_main/template/header'); ?>
<?php $this->load->view('gw/gw_main/template/middle'); ?>//i want to refresh only this part.
<?php $this->load->view('gw/gw_main/template/bottom'); ?>
<?php $this->load->view('gw/gw_main/template/footer'); ?>

You could use Ajax to refresh the view, not sure if your familiar with jQuery however check the load method here

Another method would be to use an iframe and have that particular view set to a refresh rate.

As Otemu alluded to, this cannot be done with standard PHP/html.

When a user requests a page a few things happen:
- User clicks a link/page on your site
- The browser gets this url, and passes it to your server
- The server runs the request to get the details of that page (this is where codeigniter starts, your controller runs, pulls any data it needs to from a model, and passes variables to your views via the $data variable you pass to them. The views are constructed, and then your server passes the html from it back to the browser of the user.

So you can set it's a very "set in stone" process:
Browser request page, server makes it, passes back to browser for display.

To dynamically re/load new content into the browser without a page refresh you need to make use of one of the two technologies mentioned by Otemu. They basically go to the server and say, "please give me this little bit of information, but without refreshing the page". When it comes back, it will either replace existing content, or just be inserted somewhere (depending on how you've set it up).

i know these ..... but someone told me that it is possible in codeigniter to load specific view part without whole page load, (codeigniters' jquery modification)....i have searched about it on net but could not find anything about that...that is why i was asking here.....by the way thanks for you all peoples' effrt.....

They misunderstood or were wrong.

The only way CI can load a "view partial" is by
<?php $this->load->view('gw/gw_main/template/middle'); ?>
And CI doesn't know if its a partial or not; it only knows it's a view.

So, you'd need an ajax function that calls some CI method that returns only that view, and in the callback of the ajax function replace the html on the page with the returned html from your function.

There is nothing in CI that does this "automatically"

thanks....yeah i was trying to do that with jquery/ajax way.......thanks you for your explanation, it will help me!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.