require_once与模板的问题 [英] require_once problem with templating
问题描述
我有 警告:require_once (1)[function.require-once]:未能打开流:没有这样的文件或目录在/Users/MyName/Sites/MySite/Views/master.php在第15行 以前没有发生过。 (文件都在根文件夹中)。我没有看到问题是什么,因为它们在同一个文件夹中 - 我不必返回 谢谢。 注释你说你的代码是: 请尝试省略or die - > ist,因为require_once会触发致命的错误,如果文件没有找到。 编辑2:解释为什么发生这种情况: 由于require_once不是函数,而是php中的语句,所以大括号是可选的,php解释上面是一个布尔表达式,其中字符串header.php被计算为布尔值true。 True被转换为一个字符串(导致为1),并且这个字符串被传递回来需要一次。 所以上面的代码被解释为 希望这有帮助;) Im new to MVC and I'm re-doing a lot of my code. I have Both Warning: require_once(1) [function.require-once]: failed to open stream: No such file or directory in /Users/MyName/Sites/MySite/Views/master.php on line 15 Fatal error: require_once() [function.require]: Failed opening required '1' (include_path='.:') in /Users/MyName/Sites/MySite/Views/master.php on line 15 This did not happen before. (Files were all in root folder). I don't see what the problem is though, since they are in the same folder - I don't have to go back Thanks. In your comment you say your code is: please try leaving out the "or die" -> ist is not necessary, because require_once will trigger a fatal error if the file is not found. Edit:
I tested it, leave out the "or die" and it will work. Edit 2: Explanation why this happened:
The above code can also be written like this: Because require_once is not a function, but a statement in php, the braces are optional, php interprets the above as a boolean expression, where the string "header.php" gets evaluated to the boolean "true". True gets cast to a string (resulting in "1"), and this string gets passed back to require once. So the above code gets interpreted as Here is how it gets interpreted step by step: hope this helps ;) 这篇关于require_once与模板的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! master.php $ c
$ p $ <?php require_once(header.php); $ c> ?>
master.php
和 header.php
是在同一个文件夹中,但我得到以下错误:
lockquote
致命错误:require_once()[function.require]:在第15行的/Users/MyName/Sites/MySite/Views/master.php中打开所需的'1'(include_path ='.:')失败p>
'../'
或引用任何其他文件夹。我在这里错过了什么?
<?php require_once(header.php)or die; ?>
编辑:
我测试了它,离开了或死,它将工作。
上面的代码也可以这样写:
require_once((header.php)or die());
$ b $ pre $ require_once(1)
$ p $ ((header.php)or die($ ))=(TRUE或die())
(TRUE或die())= TRUE
(string)TRUE ='1';
master.php
(index) which has:<?php require_once("header.php"); ?>
master.php
and header.php
are in the same folder yet I get the following error:
'../'
or reference any other folders. What am I missing here?<?php require_once("header.php") or die; ?>
require_once ( ("header.php") or die() );
require_once("1")
(("header.php") or die()) = (TRUE or die())
(TRUE or die()) = TRUE
(string) TRUE = '1';