在我的app.php中,我得到了
<?php
use Cart\App;
use Illuminate\Database\Capsule\Manager as Capsule;
session_start();
require __DIR__ . '/../vendor/autoload.php';
$app = new App;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'cart',
'username' => 'root',
'password' => 'root',
'charset' =>'utf8',
'collation' =>'utf8_unicode_ci',
'prefix' => ''
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();
require __DIR__ . '/../app/routes.php';
在我的HomeController.php中,我得到了这个
<?php
namespace Cart\Controllers;
use Slim\Views\Twig;
use Cart\Models\Product;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
class HomeController
{
public function index(Request $request, Response $response, Twig $view, Product $product)
{
$products = $product->get();
var_dump($products);
die();
return $view->render($response, 'home.twig');
}
}
如果在localhost / cart / public中运行它 我收到此错误消息:
SQLSTATE [HY000] [1045]用户'root'@'localhost'的访问被拒绝 (使用密码:是)(SQL:从
products
中选择*)
为什么这不能识别我的本地主机? 我用xamppp