我正在尝试使用Apicli创建一个从命令行运行的脚本。
include '../../atk4/loader.php';
$api=new ApiCLI('reportes');
$api->addLocation('atk4-addons',array(
'php'=>array(
'mvc',
'misc/lib',
)))->setParent($api->pathfinder->base_location);
$api->dbConnect();
$db = $this->api->db->dsql()
->table('test t')
->do_getAssoc();此命令的输出为
PHP Fatal error: Uncaught exception 'ExceptionNotConfigured' with message 'You must specify $config['dsn'] in your config.php' in /var/www/ossec/atk4/lib/ApiCLI.php:238
Stack trace:
#0 /var/www/ossec/atk4/lib/ApiCLI.php(276): ApiCLI->getConfig('dsn')
#1 /var/www/ossec/page/crons/reportes.php(13): ApiCLI->dbConnect()
#2 {main}
thrown in /var/www/ossec/atk4/lib/ApiCLI.php on line 238这是否显示为config-default.php?我添加了
$config['dsn']='mysql://user:pass@localhost/test';但它不起作用。
感谢所有人
发布于 2012-08-15 22:36:39
查看ApiCli.php和db定义,我已经通过方法传递了参数
$api->dbConnect('mysql://user:pass@localhost/test');现在它运行得很好。
致敬Alejandro
发布于 2014-05-21 03:59:38
您可以通过更改执行cron的当前目录来解决此问题。将以下行添加到文件的开头,该文件由cron执行:
$_SERVER['HTTP_HOST'] = 'site_name';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['REQUEST_METHOD'] = 'GET';
chdir('/home/user/...path_to_directory'); 发布于 2012-08-16 17:51:58
ApiCLI读取config-default,然后读取config.php文件(来自ApiCLI的代码),所以它应该选择您的配置文件。最有可能的是,它在错误的目录中查找,因为它检查当前目录:
function getConfig($path, $default_value = undefined){
/**
* For given path such as 'dsn' or 'logger/log_dir' returns
* corresponding config value. Throws ExceptionNotConfigured if not set.
*/
if(is_null($this->config)){
$this->readConfig('config-default.php');
$this->readConfig();
}
......
}
function readConfig($file='config.php'){
$orig_file = $file;
if(is_null($this->config))$this->config=array();
$config=array();
if(strpos($file,'/')===false){
$file=getcwd().'/'.$file;
// ^^^^^^^
}
...
}https://stackoverflow.com/questions/11970821
复制相似问题