在CodeIgniter中创建主模板 [英] creating a master template in CodeIgniter

查看:104
本文介绍了在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" />
    }
}

希望它有帮助。

这篇关于在CodeIgniter中创建主模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆