A
A
Anton Antonov2015-08-02 13:06:23
CodeIgniter
Anton Antonov, 2015-08-02 13:06:23

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

3 answer(s)
Z
Zex0n, 2015-08-06
@Zex0n

Directly in the template you write:

<?php include ("header.php"); ?>
<br><br><br><br><br><br><br>
<?php include ("footer.php"); ?>

header.php and footer.php are in the same place in the templates folder

K
krypt3r, 2015-08-06
@krypt3r

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);

And the page.php file code
<?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 */

V
Vasily Bodnaryuk, 2015-08-07
@Vasilesk

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 question

Ask a Question

731 491 924 answers to any question