Yii文件包含不起作用,而我可以通过键入URL来访问它 [英] Yii file include does not work, while i can access it by typing in URL
问题描述
我遇到包含/要求的问题。
I'm having an issue with an include/require.
我在我的根文件中创建了一个目录:
I made a dir in my root file:
root/includes
root/includes/something.inc.php
现在我尝试在我的webapp中包含/要求该文件:
Now i try to include/require that file into my webapp:
require(Yii::app()->baseurl.'/includes/something.inc.php');
但它说无法打开流:没有这样的文件或目录
当我去 mydomain / includes / something.php
时,它就可以了。
When i go to mydomain/includes/something.php
it just works.
为什么我为什么不能包含/要求这个文件?
Why o why can't I include/require this file?
推荐答案
Yii(1)为各种路径提供多个快捷方式。最常用的一个是 Yii :: app() - > baseUrl
和 Yii :: app() - > basePath
。
Yii(1) offers multiple shortcuts to various paths. The most commonly used one are available as Yii::app()->baseUrl
and Yii::app()->basePath
.
两种快捷方式都有不同的用途,可以在不同的级别上运行。 baseUrl
表示您的应用程序可在网上获得的网址。如果您想通过 public 网址链接资源和文件,它是否有用。 basePath
作用于文件系统级别。包含几乎都是在文件系统级别完成的。这种不匹配是导致问题的原因。
Both shortcuts serve different purposes and act on a different level. baseUrl
represents the url your application is available from on the web. And has it's use if you want to link assets and files by their public url. basePath
acts on the filesystem level. Includes are almost ever done on the filesystem-level. This mismatch is the cause of your problem.
参考:
- CApplication::$basePath
- CApplication::$baseUrl
这篇关于Yii文件包含不起作用,而我可以通过键入URL来访问它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!