Answer the question
In order to leave comments, you need to log in
How to make a generic template in CodeIgniter?
Is it possible to implement so that the header and footer files are common to all views?
The option in each controller is not of interest to them.
Answer the question
In order to leave comments, you need to log in
Directly in the template you write:
<?php include ("header.php"); ?>
<br><br><br><br><br><br><br>
<?php include ("footer.php"); ?>
I did this in one project. All controller methods (except those related to AJAX) ended with something like this
$this->view_data = array (
'page_title' => 'Some title', // текст, идущий в <h1>
'page_content' => 'view_dir/view_name', // путь к нужной вьюхе относительно каталога views
// куча других переменных, идущих во вьюху
);
$this->load->view ('page', $this->view_data);
<?php
$page = array (
'layout/header', // путь к общему хэдеру
$page_content, // контент
'layout/footer' // путь к общему футеру
);
foreach ($page as $item) {
$this->load->view ($item);
}
/* End of file page.php */
/* Location: ./application/views/page.php */
You can write a special model or library through which to produce output.
For example, I made the Theme library for output. It has 3 main methods: one adds paths to various views in the head area to the array, the other - in the body, the third one performs the output: header.php, what we added to the head array, head_body_seporator.php, what we added to array body, footer.php.
Here you can find the code for the library itself.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question