symfony框架,怎么配置默认的mysql数据库

symfony框架,怎么配置默认的mysql数据库,第1张

在 databases.yml编写配置如下:

# MySQL. Versions 4.1 and 5.0 are recommended.

#

# Install the MySQL driver:

# gem install mysql2

#

# And be sure to use new-style password hashing:

# http://dev.mysql.com/doc/refman/5.0/en/old-client.html

development:

adapter: mysql2

encoding: utf8

reconnect: false

database: test-mysql2_development

pool: 5

username: root

password:

socket: /tmp/mysql.sock

# Warning: The database defined as "test" will be erased and

# re-generated from your development database when you run "rake".

# Do not set this db to the same as development or production.

test:

adapter: mysql2

encoding: utf8

reconnect: false

database: test-mysql2_test

pool: 5

username: root

password:

socket: /tmp/mysql.sock

production:

adapter: mysql2

encoding: utf8

reconnect: false

database: test-mysql2_production

pool: 5

username: root

password:

socket: /tmp/mysql.sock

在控制器中 获取 你要渲染的值

$data = $this->getDoctrine()->getRepository("BUNDLE_NAME:ENTITY_NAME")->findAll()

return $this->render("path",['data' =>$data])

在twig中

{% for item in data %}

{{ item.id }}

{% endfor %}

如果数据不是数组的话 直接

{{ data.id }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/10034253.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-04
下一篇 2023-05-04

发表评论

登录后才能评论

评论列表(0条)

保存