(Yaf >=1.0.0)
Yaf_Loader::import — Load a PHP script
Load a PHP script file once. If the file is not an absolute path, it is looked up under the local library directory.
A file is only included once; calling Yaf_Loader::import() again with the same file returns true without re-including it.
fileThe file to load.
Returns true on success (including when the file was already loaded), or false on failure.
Beispiel #1 Yaf_Loader::import() example
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract
{
public function _initHelpers()
{
/* a relative path is looked up under the library
* directory, i.e. APPLICATION_PATH/library/functions/format.php */
Yaf_Loader::import("functions/format.php");
}
}
?>Beispiel #2 A file is imported only once
<?php
/* an absolute path is used as-is */
Yaf_Loader::import("/var/www/shop/application/library/Legacy/csv_export.php");
/* importing the same file again does nothing and returns true */
var_dump(
Yaf_Loader::import("/var/www/shop/application/library/Legacy/csv_export.php")
);
?>Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:
bool(true)