如何在CodeIgniter中组织模板结构? [英] How do you organize your template structure in CodeIgniter?

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

问题描述

我将为我的最终Web开发课程项目构建一个CMS,我的老师在MVC系统中创建它,现在我将使用CodeIgniter。



因此,我想知道如何组织您的文件/文件夹结构。



我将使用一个简单的模板系统:
- 现在我有一个正在自动加载的templates.php配置文件,并说明所选模板的名称和它的绝对路径。
- templates文件夹在views文件夹(这是最正确的方法来做这个?)
- 现在我有一些问题,通过视图中的文件访问.css文件, ,从我读过的人通常把所有的文件在应用程序文件夹之外。



你通常做什么?而且,看到我正在建设什么,你能给我什么建议?
应该不是视图包含模板中的所有东西? (包括模板文件夹中的CSS)



谢谢。



代码点击器2.1.0)



编辑:



现在,和文件夹,我在一个困境。我在constants.php中添加了以下内容:

 <! -  language:lang-php  - > 
$ config ['selected_template'] ='oceania';
$ config ['template_abs_path'] ='assets / templates /'.$ config ['selected_template'];

define('IMAGES_PATH',$ config ['template_abs_path']。'/ img /');
define('CSS_PATH',$ config ['template_abs_path']。'/ css /');
define('SCRIPTS_PATH',$ config ['template_abs_path']。'/ js /');

(如果我没有定义selected_template和template_abs_path我可以在常量中使用) / p>

我将它们包含在HTML中,如下所示:

  <! -  language:lang-html  - > 
< link rel =stylesheettype =text / csshref =<?= CSS_PATH;?> style.css/>

但现在,我试图获取一个标题存储在配置中,但我不能它,因为我需要所有这些变量在我之前创建的其他templates.php文件,否则它不会识别我的变量。 (我有模板自动加载)



templates.php

  ! -  language:lang-php  - > 
<?php if(!defined('BASEPATH'))exit('不允许直接脚本访问);

$ config ['title'] ='网站标题';
$ config ['selected_template'] ='oceania';
$ config ['template_abs_path'] ='templates /'.$ config ['selected_template'];

header.php

 < div id =logo> 
< h1>< a href =#><?= $ this-> config-> item('title');?>< / a>< / h1> ;
< / div>

因此,我需要两个配置才能在我的网站上工作?

解决方案

一个好的文件/文件夹结构如下:

  website_folder / 
---- application /
-------- config /
------------ autoload.php
------------ config.php
--------- --- ...
-------- controllers /
------------ examples.php
------- ----- index.html
------------ welcome.php
-------- ...
---- ---- views /
------------ templates /
---------------- backend.php
---------------- frontend.php
------------ ....
------ ------ example.php
------------ index.html
------------ welcome_message.php
---- assets /
-------- css /
-------- js /
-------- images /
-------- templates /
------------ frontend /
--------------- - css /
---------------- js /
---------------- images /
------------后端/
---------------- css /
--------- ------- js /
---------------- images /
-------- uploads /
- ------- index.html
---- system /
---- user_guide /
---- index.php
---- license .txt

这只是一个建议。因此,您将在views / templates和css / js文件的assets / templates /

下拥有模板视图

I will be building a CMS for my final Web Development course project, and i've been challenged by my teacher creating it in an MVC system, and for now, I'll be using CodeIgniter.

Therefore, I would like to know how do you organize your file / folder structure.

I will be using a simple templating system: - For now I have a templates.php config file that is being autoloaded and says the name of the selected template, and the absolute path to it. - The templates folder is inside the views folder (is this the most correct way to do this?) - Right now I am having some problem to access .css files through the files in the view, and, from what I've read people usually put all that files outside the application folder.

How do you normally do it? And, as seeing what I am building, what advices can you give me? Shouldn't views contain all the stuff from templates? (including CSS inside the folder of templates)

Thanks.

(i'm using the Code Ignitor 2.1.0)

EDIT:

Right now, after structured all the files and folders, I am in a dilemma. I have added the following in constants.php

<!-- language: lang-php -->
$config['selected_template'] = 'oceania';
$config['template_abs_path'] = 'assets/templates/'.$config['selected_template'];

define('IMAGES_PATH', $config['template_abs_path'].'/img/' );
define('CSS_PATH', $config['template_abs_path'].'/css/' );
define('SCRIPTS_PATH', $config['template_abs_path'].'/js/' );

(if I didn't define the selected_template and template_abs_path I could play with them in the constants)

And i'm including them in the HTML like this:

<!-- language: lang-html -->
<link rel="stylesheet" type="text/css" href="<?=CSS_PATH;?>style.css" />

But now, I was trying to get a title stored in config too, but I can't do it, because I need all this variables to be in the other templates.php file that I had created previously, otherwise it will not recognize my variables. (I have templates autoloading)

templates.php

<!-- language: lang-php -->
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$config['title'] = 'Title of the website';
$config['selected_template'] = 'oceania';
$config['template_abs_path'] = 'templates/'.$config['selected_template'];

header.php

<div id="logo">
<h1><a href="#"><?=$this->config->item('title');?></a></h1>
</div>

Therefore, do I need to have both config to have it working on my website? It really doesn't make much sense for me...

解决方案

A good file/folder structure would be the below:

website_folder/
–––– application/
–––––––– config/
–––––––––––– autoload.php
–––––––––––– config.php
–––––––––––– ...
–––––––– controllers/
–––––––––––– examples.php
–––––––––––– index.html
–––––––––––– welcome.php
–––––––– ...
–––––––– views/
––––––––---- templates/
––––––––-------- backend.php
––––––––-------- frontend.php
–––––––––––– ....
–––––––––––– example.php
–––––––––––– index.html
–––––––––––– welcome_message.php    
–––– assets/
–––––––– css/
–––––––– js/
–––––––– images/
–––––––– templates/
––––––––---- frontend/
––––––––-------- css/
––––––––-------- js/
––––––––-------- images/
––––––––---- backend/   
––––––––-------- css/
––––––––-------- js/
––––––––-------- images/
–––––––– uploads/
–––––––– index.html
–––– system/
–––– user_guide/
–––– index.php
–––– license.txt 

This is just a suggestion. So you will have your template views at views/templates and your css/js files at assets/templates/

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

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