技术博客
后端

symfony学习之内置的常用命令

1

1272086709@163.com

2026年3月10日78 次阅读0 条评论

运行Symfony

*   `php bin/console server:run ` #**在命令行开启服务器**
*   `php bin/console -vvv server:run` # **在命令行开启服务器,并且监听请求打印在控制台**

#### 操作数据库

*   `php bin/console doctrine:database:create` #**根据配置文件创建对应的数据库**
*   `php bin/console doctrine:database:drop --force` #**根据配置文件强制删除数据库**
*   `php bin/console doctrine:schema:update --dump-sql`#**生成需要同步数据库结构的SQL**
*   `php bin/console doctrine:scheme:update --force` #**根据entity生成对应的数据库**
*   `php bin/console doctrine:fixtures:load` #**根据fixture载入虚拟数据**

#### 生成一个空的数据库

*   `php bin/console doctrine:database:create`

#### 删除数据库

*   `php bin/console doctrine:database:drop --force`

#### 根据表名生成entity

*   `php bin/console doctrine:mapping:import --force AppBundle xml --filter="To8toHot"`
*   `php bin/console doctrine:mapping:convert annotation src/To8to/Bundle/AppBundle/Entity --from-database --filter="To8toHot"`

#### 生成Getters和Setters

*   `php bin/console doctrine:generate:entities AppBundle/Entity/Product`

#### 生成实体 getter && setter 【重要】

*   命令:`php bin/console doctrine:generate:entities {bundleName}`
*   示例:`php bin/console doctrine:generate:entities AppBundle:SevenTest`

#### 根据已存在的数据表生成实体【重要】

*   命令:`php bin/console doctrine:mapping:import --force {bundleName} {annotation|yml|xml} `
*   示例:`php bin/console doctrine:mapping:import AppBundle annotation`
*   示例: `php bin/console doctrine:mapping:import --force CommonBundle annotation --filter="To8toAnswer" --em=to8to`

#### 扩展使用:

*   生成指定表的实体
    `php bin/console doctrine:mapping:import --force AppBundle annotation --filter="CmsInspirationList"`

#### 事件监听器

*   **`php bin/console --env="api_dev" debug:event-dispatcher`**#**查询系统内的事件监听器**

#### Entity文件操作

*   `php bin/console doctrine:generate:entity` #**通过控制台命令生成Entity和Repository**
*   `php bin/console doctrine:generate:entities` #**生成entity下所有的set和get方法**

```php
php7 bin/console doctrine:mapping:import --force CommonBundle annotation  --em=to8to
php7 bin/console doctrine:generate:entities CommonBundle:To8toNewsCenterVideo //生成具体的某个Entity的set和get方法.
*   `php bin/console doctrine:mapping:import --force ApiBundle annotation -vvv` #**根据数据库生成Entity**

#### 缓存、文件相关命令

*   `php bin/console assets:install --symlink` #**在web/bundles下建立静态资源软件.**
*   `php bin/console assetic:dump` #**转储静态文件到web下(生产模式建议执行该操作)**
*   `php bin/console cache:clear` #**清除缓存,默认为开发环境**
*   `php bin/console cache:clear --env=prod` #**清除生产环境的缓存(每次改动,都要清除才能生效)**
*   `php bin/console cache:clear --env=dev` #**清除开发环境下缓存**

#### 路由相关命令

*   `php bin/console debug:router` #**查看所有被配置的路由.**
*   `php bin/console debug:router:match /hello/a` #**查看给定的匹配的路由**

#### Controller/Bundle相关命令

*   `php bin/console generate:bundle ` #**生成bundle**
*   `php bin/console generate:controller ` #**生成controller**
*   `php bin/console generate:doctrine:crud JyCoreBundle:Browser` #**生成增删改查Controller文件**

#### 命令相关

*   `php bin/console generate:command` #**创建命令相关**
加载评论中...