【发布时间】:2013-03-12 06:35:43
【问题描述】:
要在 codeignitor 中加载外部 Javascript 文件,我正在使用
<script src="<?php echo base_url("application/js/contentslider.js"); ?>" type="text/javascript"></script>
我可以在页面的源代码中看到
<script src="http://localhost/cinifb_ci/application/js/contentslider.js" type="text/javascript"></script>
这意味着据我所知,对于我的 CSS 文件,该文件的加载方式非常相似,我使用过
<link rel="stylesheet" href="<?php echo base_url(); ?>application/css/default.css" type="text/css" />
在页面的源代码中显示为
<link rel="stylesheet" href="http://localhost/cinifb_ci/application/css/default.css" type="text/css" />
这意味着它甚至可以完美加载。 (在单击源中的外部 js/css 链接时,它显示 403 Forbidden)。但是它们的效果都没有应用到页面上。它的显示没有错误。
我已在控制器中将 URL 帮助程序加载为 $this->load->helper('url');
并将$autoload['helper'] = array('url'); 放在autoload.php 中
你能解释一下我哪里出错了。
我了解到要加载外部 JS,我们需要安装 jquery-codeigniter 库。我已经下载了它们并将相应的文件包含在我的应用程序文件夹的相应类似文件夹中。
现在当我尝试在我的控制器中包含$this->load->library('jquery'); 时,它会显示
An Error Was Encountered
Unable to load the requested class: jquery
因此,我请求您帮助我理解为什么 403 Forbidden 在我可以看到它指向 JS/CSS 文件的确切位置时显示,其次如果 jquery-codeigniter 库的安装有误,请指导我.
注意:http://ellislab.com/codeigniter/user-guide/libraries/javascript.html 没有帮助我
编辑:
jquery-codeigniter 库我放在system/libraries/javascript/
在系统 .htaccess 文件中,我写成
RewriteEngine on
RewriteRule ^$ /index.php [L]
RewriteCond $1 !^(index\.php|images|css|js|video_files|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /cinifb_ci/index.php/$1 [L]
在我写的视图中
$this->load->helper('url');
<script src="<?php echo base_url("application/js/jquery-1.8.2.js"); ?>" type="text/javascript"></script>
在控制器中
$this->load->helper('url');
$this->load->library('javascript');
$this->load->library('javascript/jquery');
$this->load->library('Jquery_ext');
再次,如果我查看源它指向正确的源,但如果我单击外部 js 文件链接,它仍然显示 403 Forbidden 错误
抱歉,帖子太长了:(
请提出建议..!
【问题讨论】:
-
你在标题中包含 jquery 文件
-
@DesertP 当然我已经将它们包含在标题本身中
-
因为我没有得到很好的回复,在我给出实时源 URL 的那一天,当然现在它可以工作了 :)
标签: php codeigniter