I'm trying to include a php file in yii framework but is not working, that's my code:
$url = Yii::app()->request->baseUrl.'/css/new/x/x/x.php';
include $url;
I tried to use require and require_once but it gives error.
I'm trying to include a php file in yii framework but is not working, that's my code:
$url = Yii::app()->request->baseUrl.'/css/new/x/x/x.php';
include $url;
I tried to use require and require_once but it gives error.
Try this:
$url = Yii::app()->basePath.'/../css/new/x/x/x.php';
include $url;
And for a more comprehensive analysis have a look at this: Yii file include does not work, while i can access it by typing in URL
First, why the PHP file is located inside the CSS folder?
If it is a helper, it could be located at protected/helpers folder. If it is a extension, it could be located at protected/extensions, and so on. I sugest you read http://www.yiiframework.com/wiki/155/the-directory-structure-of-the-yii-project-site/.
Once the file is in the correct place, you can use Yii::import() or Yii::getPathOfAlias() to include the file. This way you use alias instead of paths:
1.Define an alias. It could be done inside your entry script (index.php file):
define('COMMON_PATH', dirname(__FILE__).'/common');
Yii::setPathOfAlias('common', COMMON_PATH);
2.Import or include the file. If included file represent a class you can use Yii::import("common.path.to.your.file.inside.common.folder.YourFile"); If included file has code to be executed use Yii::getPathOfAlias() and include():
$folder = Yii::getPathOfAlias('common.path.to.your.file.inside.common.folder');
include($folder.'/file.php');
include statement includes and evaluates the specified file. Yii::import only imports a class or a directory.