Codeigniter - 正确导入JS / CSS / IMG [英] Codeigniter - import JS/CSS/IMG properly

查看:138
本文介绍了Codeigniter - 正确导入JS / CSS / IMG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的MVC学习和搜索基本的东西我发现几个意见这个问题/话题,但每个人都有不同的状态和指示...

I'm new in MVC learning and after searchin basic stuffs I found several opinions on this question/topic but everyone have different state and instructions...

任何人都知道什么是最好的地方放置资产(js / css / img)文件在Codeigniter?

Does anyone know what is best place to put assets (js/css/img) files in Codeigniter ?

我发现一些人说明放在视图文件夹,有人在webroot资产文件夹),有人在应用程序文件夹等,所以我真的很困惑..它真的取决于用户谁正在开发应用程序(所以大家放置在不同的方式)或有一个基本的遵循规则?

I found some guys stating put in view folder, someone in webroot (creating assets folder), someone inside application folder etc so I really got confused.. Does it really depends on user who is developing application (so everyone place it on different way) or there is one basic "follow rule" for that?

Codeigniter的任何专家可以正确地回答和解释什么是最好的方式来包含这些,为什么这样做?

Can any expert in Codeigniter post right answer and explain what is best way to include this ones and why to do it like that?

推荐答案

它在某种程度上归结于味道,但我的谦逊的建议是使用一个基本的引导模式,其后是许多框架,而不仅仅是codeigniter。了解如何根据主题来布置您的网站( https://github.com/twbs/bootstrap)。

It comes down to taste, to some extent, but my humble suggestion is to use a basic bootstrap pattern which is followed by many frameworks, not just codeigniter. Look at how you would lay out your website based around a theme (https://github.com/twbs/bootstrap) for example.

我不声称自己是专家,但我建议团队非常简单易懂:

I don't claim to be expert, but I suggest something very simple and easy to understand for a team:

/
/css
/js
/application
/bower_components
... 



主题布局



使用页面时,我不想考虑加载各种库和页面内容,我只想简单地使用页面。为此,我拆分内容,所以我可以加载它与以下调用:

Theme Layout

When working with a page, I don't want to have to think about loading the various libraries and page content, I just want to work simply with the page. To do this, I split the content so I can load it with the following calls:

$this->load->view('site/header'); //Load the header and all the appropriate libs

$this->load->view('/users/edit', array('
   'record' => $this->User->get($userid);   //Work with the actual page
'));

$this->load->view('/site/footer'); //Close all the tags

通常,我将库放在根目录中,使用绝对路径查看:

Typically, I lay the libraries in the root, then load them in a view using absolute paths:

<html>
....
<head>
 <script src="/js/bootstrap.min.js"></script>
 <link href="/css/bootstrap.css" rel="stylesheet">
 </head>
...
<body>
 <navbar>
  ...
 </navbar>
<div id="content">



/application/view/site/footer.php



/application/view/site/footer.php

 </content>
 ... closing tags
 </html>



回购示例



在此处设置免费主题: https://github.com/DesertLynx/blank_CI

这篇关于Codeigniter - 正确导入JS / CSS / IMG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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