在CodeIgniter中创建主模板
嘿,我被困在一个非常基本的问题,确定问题是,我想要一个主模板,其中我可以调用头,主体和页脚。我无法发送标题和css在标题,以及如何我可以发送多个css文件。我正在这样做:
Hey guys i am stuck with a very basic problem, ok the problem is this that i want a master template in which i can call the header, body and footer. I am unable to send title and css in header and also how can i send multiple css files. I am doing something like this:
这是控制器中的代码
$data['title'] = 'Login To WePOS';
$data['css'] = base_url().'style/login-box.css';
$this->load->view('templates/default',$data);
这是标题中的代码
<head>
<title><?php echo $title ?> - CodeIgniter 2 Tutorial</title>
<link href=" <?php echo $css;?>" rel="stylesheet" type="text/css" />
</head>
这是模板名称中的代码默认 b
$ b
This is the code in template name as default
<html>
<?php
$this->load->view('templates/header', $data);
?>
<body>
<?php
$this->load->view('login/index', $data);
?>
</body>
<?php
$this->load->view('templates/footer', $data);
?>
</html>
hi在codeigniter中使用模板有不同的方法。
hi there is different method to use template in codeigniter .
您可以使用此程序
在控制器
In controller
$data['main_content'] = 'login_view';
$data['title'] = 'Login To WePOS';
$data['css'] = 'login-box.css';
$this->load->view('templates/default',$data);
在template.php视图中
$this->load->view('header_view');
$this->load->view($main_content);
$this->load->view('footer_view');
在您的主要内容变量中,您可以传递视图文件
in your main content variable you can pass the view file
如果要添加多个css或多个js文件,可以使用MY_MARK想法作为
if you want to add multiple css or multiple js files you can use MY_MARK idea as
$data['cssFiles'] = array(
'login-box.css',
'other.css'
);
和您的头文件
if(is_array($cssFiles)){
foreach($cssFiles as $cssFile) {
<link href="<?php echo base_url() . 'style/' . $css; ?>" rel="stylesheet" type="text/css" />
}
}
希望它有帮助。