[英]creating a master template in CodeIgniter
I am stuck with a very basic problem.我遇到了一个非常基本的问题。 Ook 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.我无法在标题中发送标题和 css 以及如何发送多个 css 文件。 I am doing something like this:我正在做这样的事情:
This is the code in controller这是控制器中的代码
$data['title'] = 'Login To WePOS';
$data['css'] = base_url().'style/login-box.css';
$this->load->view('templates/default',$data);
This is the code in header这是标题中的代码
<head>
<title><?php echo $title ?> - CodeIgniter 2 Tutorial</title>
<link href=" <?php echo $css;?>" rel="stylesheet" type="text/css" />
</head>
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 there is different method to use template in codeigniter .嗨,在 codeigniter 中使用模板有不同的方法。
1- you can use this procedure 1-您可以使用此程序
In controller在控制器中
$data['main_content'] = 'login_view';
$data['title'] = 'Login To WePOS';
$data['css'] = 'login-box.css';
$this->load->view('templates/default',$data);
In template.php View在 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在您的主要内容变量中,您可以传递视图文件
if you want to add multiple css or multiple js files you can use MY_MARK idea as如果你想添加多个 css 或多个 js 文件,你可以使用 MY_MARK 想法作为
$data['cssFiles'] = array(
'login-box.css',
'other.css'
);
and in your header file并在您的头文件中
if(is_array($cssFiles)){
foreach($cssFiles as $cssFile) {
<link href="<?php echo base_url() . 'style/' . $css; ?>" rel="stylesheet" type="text/css" />
}
}
Hope it helps.希望能帮助到你。
You don't have to pass $data again in your default template.您不必在默认模板中再次传递 $data。
<html>
<?php $this->load->view('templates/header'); ?>
<body>
<?php $this->load->view('login/index'); ?>
</body>
<?php $this->load->view('templates/footer'); ?>
</html>
This should allow you to pick up the $title and $css variables in your header as you have got currently.这应该允许您在当前获得的标题中选择 $title 和 $css 变量。
With regards to sending multiple css files, create an array of files, like:关于发送多个 css 文件,创建一个文件数组,如:
$data['cssFiles'] = array(
'login-box.css',
'other.css'
);
And modify the code in your header to be:并将标题中的代码修改为:
foreach($cssFiles as $cssFile) {
<link href="<?php echo base_url() . 'style/' . $css; ?>" rel="stylesheet" type="text/css" />
}
Hope that helps...希望有帮助...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.