【发布时间】:2026-02-04 09:25:01
【问题描述】:
给定文件结构并使用 WAMP
www
application
\views
\templates
header.php
assets
\js
index.js
\css
index.css
我试图按照此解决方案中给出的示例Codeigniter: How to include javascript files 进行操作,但是我没有成功。
header.php
<html>
<head>
<?php $this->load->helper('url');?>
<script type="text/javascript" src="<?php echo base_url();?>assets/js/index.js" ></script>
<title>CodeIgniter Tutorial</title>
</head>
<body>
<h1><?php echo $title ?></h1>
浏览器中抛出的错误是
GET http://localhost/index.php/localhost/assets/js/index.js 404 (Not Found)
header.php 正在被调用,因为它是我唯一一个带有 js 引用的 php 文件,抱歉,如果我误解了其他人的解决方案,我真的不明白为什么它不起作用
【问题讨论】:
-
所以这就是你的基本 url
http://localhost/index.php/localhost/这似乎不正确。 -
尝试访问
http://localhost/index.php/assets/js/index.js看看是否正常? -
$config['base_url'] = 'localhost';刚刚尝试使用 src="assets/js/index.js"; 访问localhost/index.php/assets/js/index.js没有运气
-
试试这个:
<script type="text/javascript" src="<?php echo site_url(); ?>assets/js/index.js"></script> -
顺便说一句,您的配置文件中的站点 url 是什么?
标签: php codeigniter