codeigniter 4 在 include, include_once, require, require_once 之后返回 1
codeigniter 4 is returning 1 after include, include_once, require, require_once
当我使用上面提到的(包括,include_once,要求,require_once)方法时,我在我使用它的每个内容的末尾都写了 1 .
看看:
PHP Code:
<!--Footer Section Starts Here-->
<?= require_once("elements/footer.php"); ?>
<!--Footer Section Ends Here-->
<!--Bottom CSS and JS Starts Here-->
<?= include_once("elements/bottom_css_and_js.php"); ?>
<!--Bottom CSS and JS Ends Here-->
Html Output
<div>
<div>
<p class="copyright">Copyright ©<script>document.write(new Date().getFullYear());</script> All rights reserved.</p>
</div>
<div>
<p class="copyright">This template is made with <i class="ion-ios-heart text-red" aria-hidden="true"></i> by <a href="http://localhost:8080/codeigniter4">Localhost</a></p>
</div>
</div>1
<!--Bottom CSS and JS Starts Here-->
<script src="http://localhost:8080/codeigniter4/public/assets/js/jquery.min.js"></script>
<script src="http://localhost:8080/codeigniter4/public/assets/js/popper.js"></script>
<script src="http://localhost:8080/codeigniter4/public/assets/bootstrap-footer-19/js/bootstrap.min.js"></script>
<script src="http://localhost:8080/codeigniter4/public/assets/js/main.js"></script>
</body>
</html>1
<!--Bottom CSS and JS Ends Here-->
这是为了扩展@sergiy T 的评论(答案)和 OP 的评论,“不,它不起作用......”
当前密码为
<!--Footer Section Starts Here-->
<?= require_once("elements/footer.php"); ?>
<!--Footer Section Ends Here-->
<!--Bottom CSS and JS Starts Here-->
<?= include_once("elements/bottom_css_and_js.php"); ?>
<!--Bottom CSS and JS Ends Here-->
由于使用 = 的短代码形式,您在哪里回显对 require_once 和 include_once 等的调用结果。所以你会看到代码被“包含”,函数调用的结果也是 1.
因此您需要删除回显,因为执行 require 或 include 将内联代码设为 executed/displayed。
所以你需要把它改成...
<!--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-->
一如既往,建议阅读 php.net
中这些函数的作用
当我使用上面提到的(包括,include_once,要求,require_once)方法时,我在我使用它的每个内容的末尾都写了 1 .
看看:
PHP Code:
<!--Footer Section Starts Here-->
<?= require_once("elements/footer.php"); ?>
<!--Footer Section Ends Here-->
<!--Bottom CSS and JS Starts Here-->
<?= include_once("elements/bottom_css_and_js.php"); ?>
<!--Bottom CSS and JS Ends Here-->
Html Output
<div>
<div>
<p class="copyright">Copyright ©<script>document.write(new Date().getFullYear());</script> All rights reserved.</p>
</div>
<div>
<p class="copyright">This template is made with <i class="ion-ios-heart text-red" aria-hidden="true"></i> by <a href="http://localhost:8080/codeigniter4">Localhost</a></p>
</div>
</div>1
<!--Bottom CSS and JS Starts Here-->
<script src="http://localhost:8080/codeigniter4/public/assets/js/jquery.min.js"></script>
<script src="http://localhost:8080/codeigniter4/public/assets/js/popper.js"></script>
<script src="http://localhost:8080/codeigniter4/public/assets/bootstrap-footer-19/js/bootstrap.min.js"></script>
<script src="http://localhost:8080/codeigniter4/public/assets/js/main.js"></script>
</body>
</html>1
<!--Bottom CSS and JS Ends Here-->
这是为了扩展@sergiy T 的评论(答案)和 OP 的评论,“不,它不起作用......”
当前密码为
<!--Footer Section Starts Here-->
<?= require_once("elements/footer.php"); ?>
<!--Footer Section Ends Here-->
<!--Bottom CSS and JS Starts Here-->
<?= include_once("elements/bottom_css_and_js.php"); ?>
<!--Bottom CSS and JS Ends Here-->
由于使用 = 的短代码形式,您在哪里回显对 require_once 和 include_once 等的调用结果。所以你会看到代码被“包含”,函数调用的结果也是 1.
因此您需要删除回显,因为执行 require 或 include 将内联代码设为 executed/displayed。
所以你需要把它改成...
<!--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-->
一如既往,建议阅读 php.net
中这些函数的作用