Codeigniter how to create a template

im trying to get into codeigniter MVC, but I don’t know how to make my template, so I have 2 files (header and footer), and then I can make my controllers and then ONLY put the information in the "content" div, so i include top and heading a good way like this

<?php
include("header.php");
?>
<div id="content">My content here</div>

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

hope you understand what i mean and can help me :)

+3
source share
4 answers

It’s best to upload views to your views.

Inside the views /content.php:

<? $this->view('header', array('title'=>'The page title', 'keywords'=>'some keywords', 'etc'=>'...')); ?>
<div id="content">My content here</div>
<? $this->view('footer'); ?>

So, in your controller you will do the following:

$this->load->view('content', $data);

$data may contain a “title” or “keywords” and which will be implemented as such in your controller:

$data['title'] = 'title';
$data['keywords' = 'keywords';

"content":

<? $this->view('header', array('title'=>$title, 'keywords'=>$keywords)); ?>
<div id="content">My content here</div>
<? $this->view('footer'); ?>

-, : CodeIgniter PHP Rails

+5

. , layout.php, html , :

$this->load->view($template);

:

$data['template'] = 'filename'; 
$this->load->view('layout', $data);

, "filename" <div></div>

+2

, , . MVC.

- :

$this->load->view('header');
$this->load->view('content');
$this->load->view('footer');

, ( /system/application/views)

0

, . , $this->load->view('content', $data);

:

There is more online, try playing them :)

0
source

Source: https://habr.com/ru/post/1768502/


All Articles