我想创建一个模板codeigniter,但我不知道我做得对,这是我到目前为止所得到的...如果有人告诉我做对了吗?我正在使用codeigniter 3和bootstrap 4 ... Web应用程序也应该使用websocket作为仪表板。
模板
<div class="menu-wrap">
<?php $this->load->view('landing/menu-wrap'); ?>
</div>
<!-- Header Section Start -->
<header id="video-area" data-stellar-background-ratio="0.5">
<div id="block" data-vide-bg="video/video"></div>
<?php $this->load->view('landing/video-area'); ?>
</header>
<!-- Features Section End -->
<section id="services" class="section">
<?php $this->load->view('landing/services'); ?>
</section>
<!-- Services Section Start -->
<!-- Services Section End -->
<!-- Features Section Start -->
<section id="features" class="section" data-stellar-background-ratio="0.2">
<?php $this->load->view('landing/features'); ?>
</section>
<!-- Start Video promo Section -->
<section class="video-promo section" data-stellar-background-ratio="0.5">
<div class="overlay"></div>
<?php $this->load->view('landing/video-promo'); ?>
</section>
<!-- End Video Promo Section -->
<!-- Portfolio Section -->
<section id="portfolios" class="section">
<!-- Container Starts -->
<?php $this->load->view('landing/portfolios'); ?>
<!-- Container Ends -->
</section>
<!-- Portfolio Section Ends -->
<!-- Start Pricing Table Section -->
<div id="pricing" class="section pricing-section">
<?php $this->load->view('landing/pricing'); ?>
</div>
<!-- End Pricing Table Section -->
<!-- Counter Section Start -->
<div class="counters section" data-stellar-background-ratio="0.5">
<div class="overlay"></div>
<?php $this->load->view('landing/counters'); ?>
</div>
<!-- Counter Section End -->
<!-- testimonial Section Start -->
<div id="testimonial" class="section">
<?php $this->load->view('landing/testimonial'); ?>
</div>
<!-- testimonial Section Start -->
<!-- Download Section Start -->
<section id="download" class="section">
<?php $this->load->view('landing/download'); ?>
</section>
<!-- Download Section End -->
<!-- Blog Section -->
<section id="blog" class="section">
<!-- Container Starts -->
<?php $this->load->view('landing/blog'); ?>
</section>
<!-- blog Section End -->
<section id="contact" class="section">
<?php $this->load->view('landing/contact'); ?>
</section>
<!-- Contact Section End -->
<!-- Subcribe Section Start -->
<div id="subscribe" class="section">
<?php $this->load->view('landing/subscribe'); ?>
</div>
<!-- Subcribe Section End -->
答案 0 :(得分:3)
在codeigniter中使用模板的理想方法是这样的:
在视图文件夹中创建一个视图文件,例如 template.php
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title><?php echo site_name(); ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
....
//Load your css files here
....
</head>
<body>
// All common HTML content like header and all parent div(s) with class like container (is using bootstrap) will go here.
<!-- Wrapper Start -->
<div class="wrapper">
<div class="structure-row">
<!-- Header -->
<?php echo $this->load->view('blocks/header'); ?>
<?php echo $content; ?>
</div>
</div>
<!-- Footer -->
<?php echo $this->load->view('blocks/footer'); ?>
</body>
</html>
然后在库文件夹 Template.php
中创建一个库文件<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Template
*
* Enables the user to load template
*
* Usage:
*
* Load it within your Controllers:
* $this->load->library("Template");
*
* Configure CodeIgniter to Auto-Load it:
*
* Edit application/config/autoload.php
* $autoload['libraries'] = array('Template');
*
*
* Use it in your view files
* $this->template->view('view', $parameters);
*
*/
class Template {
var $obj;
var $template;
public function __construct($template = array('template' => 'template'))
{
$this->obj =& get_instance();
$this->template = $template['template'];
}
/**
*
* set_template()
*
* Sets the template
*
*/
public function set_template($template)
{
$this->template = $template;
}
/**
*
* view()
*
* Loads the view
*
*/
public function view($view, $data = NULL, $return = FALSE)
{
$CI = & get_instance();
$loaded_data = array();
$loaded_data['content'] = $this->obj->load->view($view, $data, true);
if ($return)
{
$output = $this->obj->load->view($this->template, $loaded_data, true);
return $output;
}
else
{
$this->obj->load->view($this->template, $loaded_data, false);
}
}
}
然后在你的config / autoload.php文件中加载上面给出的库:
$autoload['libraries'] = array('database', 'session', 'template');
现在终于可以在模板中加载自己的视图,如下所示:
$this->template->view('folder_name/view_file_name');
希望这会对你有所帮助。如果您需要更多信息,可以在评论中写下来。