��权限没有,则隐藏 function forum_list_access_filter($forumlist, $gid, $allow = 'allowread') { global $grouplist; if (empty($forumlist)) return array(); if (1 == $gid) return $forumlist; $forumlist_filter = $forumlist; $group = $grouplist[$gid]; foreach ($forumlist_filter as $fid => $forum) { if (empty($forum['accesson']) && empty($group[$allow]) || !empty($forum['accesson']) && empty($forum['accesslist'][$gid][$allow])) { unset($forumlist_filter[$fid]); } unset($forumlist_filter[$fid]['accesslist']); } return $forumlist_filter; } function forum_filter_moduid($moduids) { $moduids = trim($moduids); if (empty($moduids)) return ''; $arr = explode(',', $moduids); $r = array(); foreach ($arr as $_uid) { $_uid = intval($_uid); $_user = user_read($_uid); if (empty($_user)) continue; if ($_user['gid'] > 4) continue; $r[] = $_uid; } return implode(',', $r); } function forum_safe_info($forum) { //unset($forum['moduids']); return $forum; } function forum_filter($forumlist) { foreach ($forumlist as &$val) { unset($val['brief'], $val['announcement'], $val['seo_title'], $val['seo_keywords'], $val['create_date_fmt'], $val['icon_url'], $val['modlist']); } return $forumlist; } function forum_format_url($forum) { global $conf; if (0 == $forum['category']) { // 列表URL $url = url('list-' . $forum['fid'], '', FALSE); } elseif (1 == $forum['category']) { // 频道 $url = url('category-' . $forum['fid'], '', FALSE); } elseif (2 == $forum['category']) { // 单页 $url = url('read-' . trim($forum['brief']), '', FALSE); } if ($conf['url_rewrite_on'] > 1 && $forum['well_alias']) { if (0 == $forum['category'] || 1 == $forum['category']) { $url = url($forum['well_alias'], '', FALSE); } elseif (2 == $forum['category']) { // 单页 $url = ($forum['threads'] && $forum['brief']) ? url($forum['well_alias'] . '-' . trim($forum['brief']), '', FALSE) : url($forum['well_alias'], '', FALSE); } } return $url; } function well_forum_alias() { $forumlist = forum_list_cache(); if (empty($forumlist)) return ''; $key = 'forum-alias'; static $cache = array(); if (isset($cache[$key])) return $cache[$key]; $cache[$key] = array(); foreach ($forumlist as $val) { if ($val['well_alias']) $cache[$key][$val['fid']] = $val['well_alias']; } return array_flip($cache[$key]); } function well_forum_alias_cache() { global $conf; $key = 'forum-alias-cache'; static $cache = array(); // 用静态变量只能在当前 request 生命周期缓存,跨进程需要再加一层缓存:redis/memcached/xcache/apc if (isset($cache[$key])) return $cache[$key]; if ('mysql' == $conf['cache']['type']) { $arr = well_forum_alias(); } else { $arr = cache_get($key); if (NULL === $arr) { $arr = well_forum_alias(); !empty($arr) AND cache_set($key, $arr); } } $cache[$key] = empty($arr) ? '' : $arr; return $cache[$key]; } ?>php - codeigniter javascript not found error - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - codeigniter javascript not found error - Stack Overflow

programmeradmin1浏览0评论

First of all, I am sorry for my bad english, I am spanish and I am sorry if I have made something wrong, this is my first post.

I have a problem with loading a javascript file in codeigniter 2.1.4. I didn´t get loaded it in the header of my page. The css files were well loaded. This example attempts to load jquery and bootstrap.

I am following the steps in the documentation of codeigniter and when I create the codeigniter static page "home.php" I want to use bootstrap for design.

The tutorial I followed is this: .html

My folder structure :

  • htdocs
    • myproject (curriculos)
      • application
        • controller
          • pages.php
        • views
          • templates
            • header.php
          • pages
            • home.php
            • about.php
      • system
      • assets
        • bootstrap
          • css
            • bootstrap.min.css
          • js
            • bootstrap.min.js
        • jquery- 2.1.0.min.js

I have been searching in this forum and others and always I find the same example with base_url() or site_url(). These are mine:

Updated code:

<script type="text/javascript" src="<?php echo base_url(); ?>assets/bootstrap/js/bootstrap.min.js"></script>

My autoload.php with url helper loaded:

$ autoload['helper'] = array('url');

When I try to load the page I get these errors:

GET http://localhost/curriculos/assets/jquery-2.1.0.min.js 404 (Not Found)
GET http://localhost/curriculos/assets/bootstrap/js/bootstrap.min.js 404 (Not Found)
GET http://localhost/curriculos/assets/bootstrap/js/bootstrap.min.js 404 (Not Found) 

The strangest is that when you click on one of them it shows you that the file type is trying to be loaded as a text/html and not as an application/javascript as usual:

Can you help me?

Thank you very much for your reply.

First of all, I am sorry for my bad english, I am spanish and I am sorry if I have made something wrong, this is my first post.

I have a problem with loading a javascript file in codeigniter 2.1.4. I didn´t get loaded it in the header of my page. The css files were well loaded. This example attempts to load jquery and bootstrap.

I am following the steps in the documentation of codeigniter and when I create the codeigniter static page "home.php" I want to use bootstrap for design.

The tutorial I followed is this: http://ellislab./codeigniter/user-guide/tutorial/static_pages.html

My folder structure :

  • htdocs
    • myproject (curriculos)
      • application
        • controller
          • pages.php
        • views
          • templates
            • header.php
          • pages
            • home.php
            • about.php
      • system
      • assets
        • bootstrap
          • css
            • bootstrap.min.css
          • js
            • bootstrap.min.js
        • jquery- 2.1.0.min.js

I have been searching in this forum and others and always I find the same example with base_url() or site_url(). These are mine:

Updated code:

<script type="text/javascript" src="<?php echo base_url(); ?>assets/bootstrap/js/bootstrap.min.js"></script>

My autoload.php with url helper loaded:

$ autoload['helper'] = array('url');

When I try to load the page I get these errors:

GET http://localhost/curriculos/assets/jquery-2.1.0.min.js 404 (Not Found)
GET http://localhost/curriculos/assets/bootstrap/js/bootstrap.min.js 404 (Not Found)
GET http://localhost/curriculos/assets/bootstrap/js/bootstrap.min.js 404 (Not Found) 

The strangest is that when you click on one of them it shows you that the file type is trying to be loaded as a text/html and not as an application/javascript as usual:

Can you help me?

Thank you very much for your reply.

Share Improve this question edited Jul 26, 2017 at 17:08 Cœur 38.8k26 gold badges205 silver badges277 bronze badges asked Apr 11, 2014 at 16:35 mrroot5mrroot5 1,9713 gold badges28 silver badges33 bronze badges 4
  • are the images working fine or the same is the problem with the images? – Guns Commented Apr 11, 2014 at 16:40
  • I uploaded a new image with new suggestions.Is this your question? Maybe I didn't understand you well. – mrroot5 Commented Apr 11, 2014 at 23:39
  • Sorry for my english, now I think that I understand you. Yes, the image is correct for the new updated code. Sorry, my text editor teased me when I copied my question from the editor to stack overflow. – mrroot5 Commented Apr 11, 2014 at 23:46
  • I found the problem. The problem is the .htaccess from codeigniter to hide index.php in url ¬¬. This is my .htaccess: RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ index.php/$1 [L] Someone knows how to change the .htaccess to admit .js files? @Guns @Jai @shan22 – mrroot5 Commented Apr 11, 2014 at 23:52
Add a ment  | 

4 Answers 4

Reset to default 5

You need to change your .htaccess file so that it no longer rewrites requests made to '/assets'.

In other words, you need your .htaccess file to ignore requests to the 'assets' folder and just let the browser load the url as provided. Try this:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|assets|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
<script  src="<?php echo base_url(); ?>assets/bootstrap/js/bootstrap.min.js"></script>

This is the correct path.Try it!

The problem is the .htaccess provided by codeigniter to remove the index.php. Follow this link: http://www.codeigniter./userguide2/general/urls.html

Remove this code in your .htaccess and you can load javascript files :).

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Assets folder must be outside the application folder. Like below snapshot. Then user the below code in views files to include css, js and fonts files.

Folder structure for css/js/fonts files in codeigniter

<link href="<?php echo base_url('assets/css/bootstrap.min.css'); ?>" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?php echo base_url("assets/js/jquery-1.11.3.min.js"); ?>"></script>
<script type="text/javascript" src="<?php echo base_url("assets/js/bootstrap.js"); ?>"></script>
发布评论

评论列表(0)

  1. 暂无评论