I develop a project with Yii.
I need to require a plain .php file (not component, not a class, just a regular sequence of PHP functions definitions). What is the correct way to do this under Yii framework? Should I use plain require_once()?
require_once(Yii::app()->basePath . '/extensions/my-php-file.php');
Right?
Yes, that's correct.
Example:
Method in your question is fine, but forces file location to be always in same folder.
Flexible
Yii::import
is intented for loading classes only, and only classes whose name is same as filename.However if you want to use aliases to get path to file, you can still benefit from aliases by using
getPathOfAlias
, like that:To include file relative to current file it is good to use
dirname(__FILE__)
or__DIR__
(php 5.3+)