2
我在關注Destructy教程,在設置並測試出數據庫連接後,我得到以下錯誤:無法解決未定義的索引:outputBuffering in /vendor/slim/slim/Slim/App.php on line 252 error
到目前爲止,這是我的設置:
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();
有沒有人知道問題是爲了解決它?
我希望silentworks將推出一個更新[教程](HTTP://想法.silentworks.co.uk/slim-php-101-using-laravel-config-package /)將Laravel的Config軟件包集成到Slim 3中。 – alexw