I wrote a quick CI library class to render my pages so I wouldn\'t have to keep typing \'$this->load->view\' all the time and for DRY. Now when I re-render my contact form after
Create a view called template.php
in your views folder with the following code in it:
<?php
$this->load->view('fragments/header', $this->_ci_cached_vars); // pass $data vars
$this->load->view('fragments/navigation');
$this->load->view($view);
$this->load->view('fragments/navigation');
$this->load->view('fragments/footer');
Then use the below controller code:
public function index() {
$this->form_validation->set_rules('sender_name', 'From', 'required');
$this->form_validation->set_rules('sender_email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('subject', 'Subject', 'required');
$this->form_validation->set_rules('message', 'Message', 'required');
if ($this->form_validation->run() === FALSE) {
$data = array(
'view' => 'contact/contact',
'title' => 'Contact Me');
$this->load->view('template', $data);
}
You don't need to create a library to do this as you can just create a template view which will load the appropriate views and the specified view and pass the data along to them.