I'm learning myself codeigniter. I'm building a newssite. My website has two 'parts': a menu and the main content. The menu is static, and should not be reloaded every time.
I read something about Partials in codeigniter, but I'm a bit confused now. I have a 'general view' , like this:
general:
<!DOCTYPE html>
<?php $this->load->view('partials/page_head');?>
<body>
<div class="wrapper">
<header>
<div class="logo">Logo</div>
</header>
<?php $this->load->view('partials/menu');?>
<div id="content">
$content;
</div>
</body>
</html>
And a controller:
<?php
class News extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->helper('url');
}
public function latest() {
$this->data['content'] = 'latest';
$this->load->view('layout/general', $this->data);
}
public function detailed() {
$this->data['content'] = 'detailed';
$this->load->view('layout/general', $this->data);
}
}
But what happens if I call the latest()-function to generate my view? Does codeigniter only reload the 'content' part? Or the whole general page, including the partials. I searched the internet, but read different things about this. I know I could use ajax-calls for this, but I wanted to know If codeigniter could do the same for me?
For every page refresh, Codeigniter does an entire page refresh. In your case, when you call the
latest()
method, it will do the following:$this->data['content']
$this->data
to thegeneral
view and loadgeneral
view gets any "partials" and renders the pageThis process will happen every time you refresh the page.
Now, i know you mentioned AJAX. AJAX would be very useful if you would like to just get or obtain certain data that pertains to the page without having to reload the entire page.