后端的Codeigniter 2.2项目与几个模板 [英] backend of Codeigniter 2.2 project with several templates

查看:127
本文介绍了后端的Codeigniter 2.2项目与几个模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Codeigniter 2.2项目中,我想为后端和用户保存的数据库表创建几个模板,用于用户的模板。
当用户打开登录页面时,默认模板将打开,因为用户尚未记录。
在登录时我保存在会话当前模板名称。
但问题是,在我的配置文件我有几个块的分页布局。
不同的模板使用diffrent标签分页布局。
所以在配置文件中我要写如下:

In Codeigniter 2.2 project I want to make several templates for backend and in db table of user save which template is used for user. When User opens login page then default template is opened, as user is not logged yet. On login I save in session current template name. But problem is that in my config file I have several blocks for pagination layout. Different templates use diffrent tags for pagination layout. So in config file I have to write something like:

if ( $current_template == 'template_name' ) {
    $config['full_tag_open'] = '<p>';
    $config['full_tag_close'] = '</p>';
}...

但是看起来CI get_instance在配置文件!
这可以决定这个吗?如果有一些好的工具为此?

But it looks like that CI get_instance() method is not accessible in config file! Which can be decision for this ? If are there some good tools for this?

推荐答案

我假设你的服务器端代码是一致的, css / js否则为不同的视图,同样的方法可以扩展。

I am assuming your server side code is consistent, view is consistent just changes in css/js otherwise for different views, same methodology can be extended.

如果你是基于模板的UI,那么你应该有模块化的方法显示内容,你必须有header,footer&主要内容部分。现在如果你有不同的模板,那么你应该有不同的模板目录中的相同名称的css / js文件,如下图所示:

If you are making template based UI then you should have modular approach for displaying the contents e.g for view page you must have header, footer & main content part. Now if you have different templates then you should have css/js files in with same names in different template directories as shown in picture below:

用户登录后,在会话中保存模板名称,您的主题将是动态的,如下代码将用于加载css / js

After the user login save the template name in session and your theme will be dynamic as below code will be used to load css/js

<?php
$templateName=$this->session->userdata('currentTemplate');
?>
<link rel="stylesheet" type="text/css" href="<?php echo base_url().'ui_components'.$templateName>?>/css/style.css"/>
<script type="text/javascript" src="<?php echo base_url().'ui_components/'.$templateName?>/js/main.js"></script>

您可以尝试这种类型的简单模板系统。

You can try this type of simple templating system.

这篇关于后端的Codeigniter 2.2项目与几个模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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