CodeIgniter模板 [英] CodeIgniter templates

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

问题描述

对不起,如果它是一个愚蠢的问题,但我是一个初学者,有点失去。



对于实践我决定编码一个真正小的社交网络



我在过去的小型CodeIgniter项目工作,真的是我真的不喜欢加载每个控制器的页眉和页脚。



所以在YouTube上,我看到了一个关于创建基本模板的视频。



但我不能真正决定它是否是一个好的



在我的视图文件夹中,我创建了3个子文件夹

   -  include 
- template
- user

在模板中我有 main_template.php ,看起来像这样:

 <!DOCTYPE html& 
< html>
< head>
< meta charset =utf-8>
< link rel =stylesheettype =text / csshref =<?php base_url();?> themes / default / style.css>
< title><?php echo $ title; ?>< / title>
< / head>
< body>

< / body>
< / html>

如果每个视图需要,控制器将包含标题和其他内容的不同变量。



我的问题是:不是创建页眉和页脚文件,创建所有视图,包括html,head和body标签这样是不是好主意?

解决方案

我建议使用header和footer。否则,当你试图自定义每个模板会变得很杂乱。我把一些变量传递给视图;实际上,当设置页面的标题,元描述,JS / CSS包括等时,这将会非常方便。然而,如果你保持你的页眉/页脚在一起,你将不得不通过一个变量的整个身体或传递您想要的特定视图的名称;在这种情况下,您必须加载此主视图内的特定视图。


Hello first sorry if its a stupid question, but I amm a beginner, and im a bit lost.

For practice I decided to code a really small social network just for practice.

I worked on small CodeIgniter projects in the past, and the truth is I dont really like loading the header and footer in every controller.

So on YouTube I saw a video about creating basic templating.

But I can't really decide whether it is a good idea.

So how would it look like?

In my view folder I created 3 subfolders

- include 
- template
- user 

In the templates I have the main_template.php and that looks like this:

 <!DOCTYPE html>
 <html>
 <head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="<?php base_url();?>themes/default/style.css">
    <title><?php echo $title; ?></title>
 </head>
 <body>

</body>
</html>

The controllers would contain different variables for the title and other stuff if needed for each view.

My question is: is it a bad idea not create header and footer files, and creating all views with including the html, head, and body tag like this?

解决方案

I would recommend using a "header" and "footer". Otherwise it's going to get really messy when you'r trying to customize each template. I get passing down a few variables to the views; actually, that will come in really handy when setting the page's title, meta description, JS/CSS includes, etc. However if you keep your header/footer together, you will have to either pass the entire body in a variable or pass in the name of the specific view you want; in which case you would have to load the specific view inside this main view.

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

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