I'm trying to write to console from inside a controller:
private function _getHintsFromList($list, $curated = false) {
set_include_path(dirname(dirname(__FILE__)).'/lib'.PATH_SEPARATOR.get_include_path());
require('../../FirePHPCore/FirePHP.class.php');
$firephp = FirePHP::getInstance(true);
$firephp->fb('Hello World');
}
I am getting this error:
{"error":true,"message":"App\\Http\\Controllers\\HintController::_getHintsFromList(): Failed opening
required '..\/..\/FirePHPCore\/FirePHP.class.php' (include_path='\/var\/www\/build\/app\/Http\/lib:
.:\/usr\/share\/php:\/usr\/share\/pear')"}
I have checked multiple times and the FirePHPCore folder is 2 folders out of here the controller is located:
What am I doing wrong and how do I fix it?
Usually, you must specify included files in your index.php
file. The same is actual for autoloading
function:
index.php:
...
set_include_path(get_include_path().PATH_SEPARATOR.'app/');
function __autoload($class){ // autoloader
require_once($class.'.php');
}
...
Then you can call your function like the following:
class HintController{
...
private function _getHintsFromList($list, $curated = false) {
$firephp = \FirePHP::getInstance(true);
$firephp->fb('Hello World');
}
...
}
set_include_path()
is not useful in this case. The execution context (CLI, HTTP server, etc) must be taken in consideration.
Is much more clearer, simpler less and error prone just do something like this:
$path = dirname(dirname(__FILE__));
require $path . '/../../FirePHPCore/FirePHP.class.php';
It should work for your case. Later, you could to consider take a look to autoload
method and related matters such as PSR-4 / PSR-0.