【发布时间】:2018-01-24 12:45:38
【问题描述】:
我刚开始使用 symfony。我用树枝、学说制造者安装了 SF4……
我创建了我的数据库“Autotrader”,我创建了一个迁移并迁移了它。
但是每当我尝试从数据库中获取数据时,我都会收到以下错误:
这是我正在使用的代码:
<?php
namespace App\Controller;
use App\Entity\Car;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class CarController extends Controller
{
public function index()
{
$repository = $this->getDoctrine()->getRepository('App:Car');
$cars = $repository->findAll();
return $this->render('Car/list.html.twig', array(
"title" => "Our cars",
'cars' => $cars
));
}
}
参数配置:
parameters:
# Adds a fallback DATABASE_URL if the env var is not set.
# This allows you to run cache:warmup even if your
# environment variables are not available yet.
# You should not need to change this value.
env(DATABASE_URL): ''
doctrine:
dbal:
# configure these for your database server
driver: 'mysql'
server_version: '5.7'
charset: 'utf8mb4'
dbname: 'autotrader'
host: '127.0.0.1'
port: 3306
user: 'root'
password: 'secret'
# With Symfony 3.3, remove the `resolve:` prefix
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
【问题讨论】:
-
那里写着:“未知数据库:Autotrader”
-
是的,但是如果我检查 Sequel Pro,数据库就在那里
-
请给我们您的参数配置
-
doctrine.yaml 添加:)