二、symfony配置

来源:互联网 发布:自然辩证法与人工智能 编辑:程序博客网 时间:2024/05/22 00:35

symfony配置文件再app/config目录下


一、配置数据库:

打开app/config/parameters.yml看到如下内容:

parameters:

    database_driver: pdo_mysql  
    database_host: 127.0.0.1
    database_port: null
    database_name: dbname
    database_user: root
    database_password: null
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    locale: en
    secret: ThisTokenIsNotSoSecretChangeIt
    debug_toolbar: true
    debug_redirects: false
    use_assetic_controller: true


二、配置路由

1、配置app下的路由:

打开app/config/routing.yml

test_hello:
    resource: "@TestHelloBundle/Resources/config/routing.yml"
    prefix:   /

说明:

resource:引入bundle路由配置资源

prefix: 如果配置了,例如:“prefix:/admin” 那么在url地址访问的时候就需要加上/admin,http://localhost/admin


2、配置bundle下的路由:

\src\Test\HelloBundle\Resources\config

test_hello_homepage:
    pattern:  /hello/{name}
    defaults: { _controller: TestHelloBundle:Default:index }

说明:

test_hello_homepage:路由的名字,是由自己定义的。

pattern: 展示在url访问的地址,例如:/hello/{name},那么实际访问http://localhost/admin/hello/user

defaults: { _controller: TestHelloBundle:控制器(类名):操作(方法) }

methods: 定义请求方式,不是必须定义。例如:methods:[post]


app下的路由配置和bundle下路由配置的关系,app下的路由配置引用了bundle下的路由配置资源。




0 0
原创粉丝点击