我正在关注 Destructy 教程,在设置和测试数据库连接后,我收到以下错误:
到目前为止,这是我的设置:
return [
'settings' => [
'displayErrorDetails' => true,
],
'url' => 'http://localhost',
'db' => [
'mysql' => [
'host' => 'localhost',
'dbname' => 'destructy',
'username' => 'username',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]
],
];
这是容器的定义方式:
/*Set Slim up*/
$container = new \Slim\Container();//Ver si le afecta o no los paréntesis ()
$container['settings'] = function($c){
return $c['config']->get('settings');
};
$container['config'] = function($c){ //c= current state of our container
return new \Noodlehaus\Config('../config/app.php');//We could pass more parameters ... as an array ['param1','param2','etc']
};
$container['view'] = function($c){//c= current state of our container
$view = new Slim\Views\Twig('../resources/views');//Ubicación de las vistas
//Ability to generate URLs to routes from within our views
$view->addExtension(new \Slim\Views\TwigExtension(
$c['router'],
$c['config']->get('url')
));
return $view;
};
//base de datos:
$container['db'] = function($c){
//return new PDO('mysql:host=127.0.0.1;dbname=destructy','root','root');
return new PDO(
'mysql:host='.$c['config']->get('db.mysql.host').';dbname='.$c['config']->get('db.mysql.dbname'),
$c['config']->get('db.mysql.username'),
$c['config']->get('db.mysql.password'));
};
$app = new Slim\App($container);
require_once 'routes.php';
路线:
$app->get('/',function($request,$response,$args){
echo 'Destructy - Home.';
echo '<p style="color: darkblue">Welcome to the admin area</p>';
echo '<p>Testing access to config parameters ...</p>';
echo $this->config->get('db.mysql.host').'<br>';
echo $this->config->get('url');
/*Testing out DB connection*/
var_dump($this->db);
$this->view->render($response,'home.twig');
});
$app->run();
有谁知道问题是什么来解决它?