You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CodeIgniter4使用include/require系列函数引入文件末尾额外输出1问题

问题原因

你看到的多余字符1是错误使用PHP短输出标签导致的:
<?= 内容 ?> 等价于 <?php echo 内容; ?>,会直接输出后面表达式的返回值。而include/include_once/require/require_once执行成功时的返回值为布尔值true,布尔值转为字符串输出时就会变成1,刚好对应你每处引入语句后面多出来的字符。

解决方法

方案1:修改引入语句的写法

去掉引入语句的短输出标签,改用普通PHP标签执行引入逻辑即可,不需要echo引入函数的返回值:

<!--Footer Section Starts Here-->
<?php require_once("elements/footer.php"); ?>
<!--Footer Section Ends Here-->
<!--Bottom CSS and JS Starts Here-->
<?php include_once("elements/bottom_css_and_js.php"); ?>
<!--Bottom CSS and JS Ends Here-->

方案2:使用CodeIgniter4原生视图加载方法(更推荐)

CodeIgniter4内置了view()方法加载视图片段,自动适配框架路径规则,写法更简洁,也不会出现多余输出的问题:

<!--Footer Section Starts Here-->
<?= view("elements/footer") ?>
<!--Footer Section Ends Here-->
<!--Bottom CSS and JS Starts Here-->
<?= view("elements/bottom_css_and_js") ?>
<!--Bottom CSS and JS Ends Here-->

内容的提问来源于stack exchange,提问作者Adarsh Kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.20 14:06:08