symfony4 安装和创建项目
symfony4 安装
环境:在windows 10 上
安装 compposer
并选择一个目录执行以下命令进行 symfony 项目的创建
下载Composer 最新版本:v1.7.3
Windows Installer
安装程序将为您下载composer并设置PATH环境变量,以便您可以composer从任何目录中进行调用。
下载并运行Composer-Setup.exe - 它将在执行时安装最新的composer版本。
安装的时候需要选择你的PHP位置
用默认的就一路确定即可
cmd打开
composer --version回车查看版本
然后进入你要下载symfony的位置
// 创建名称为 my-project 的项目 会在当前目录下进行创建
$ composer create-project symfony/website-skeleton my-project
创建过程比较漫长,要等待个3-5分钟
这个是创建 项目名为:symfony 的项目的整个过程
如图则安装完成
接下来启动项目
启动symfony4 项目
$ cd my-project
// 执行以下命令启动项目
$ php bin/console server:run
打开浏览器并访问http://localhost:8000/
. 如果一切正常, 你将会看到欢迎页面. 稍后, 当你完成工作后, 在终端中按下Ctrl + c
停止服务.
symfony4框架项目目录
├── bin # 可执行文件目录 -d
│ ├── console # 命令行入口文件 用于执行很多命令,如数据库操作、缓存操作、查看路由、服务等.
│ └── phpunit # Favicon
├── config # 配置目录 -d
│ ├── packages # 遵循每个环境都有单独的配置文件目录 -d
│ │ ├── dev
│ │ ├── prod
│ │ ├── test
│ │ ├── cache.yaml
│ │ ├── doctrine_migrations.yaml
│ │ ├── doctrine.yaml
│ │ ├── framework.yaml
│ │ ├── routing-yaml
│ │ ├── security.yaml
│ │ ├── sensio_ framework_extra.yaml
│ │ ├── swiftmailer.yaml
│ │ ├── translation.yaml
│ │ ├── twig.yaml
│ │ └── validator.yaml
│ ├── routes # 路由配置文件 -d
│ │ └── dev
│ │ │ ├── twig.yaml
│ │ │ └── web_profiler.yaml
│ │ └── annotations.yaml
│ ├── bootstrap. php
│ ├── bundles. php # 类似4版本之前的bundle注册,需要使用的bundle都要在这里进行注册才能使用
│ ├── routes. yaml # 路由配置文件
│ └── services. yaml # 服务配置文件
├── public # 入口文件 -d
│ └── index.php # 项目入口文件
├── src # 应用目录 (应用不一定非得src目录,可以在composer.json的autoload处修改)
│ ├── Controller # 控制器文件目录 -d
│ ├── Entity # 数据库实体文件目录 -d
│ ├── Migrations # 数据库迁移目录 -d
│ ├── Repository # 数据实体操作类 -d
│ └── Kernel.php # symfony核心,request\response都是这里处理的,包括路由、服务容器、依赖等
├── templates # templates目录是在安装twig组件后自动创建的,是存放twig模板位置 -d
├── tests # 包含PHP写的与symfony测试框架兼容的单元与功能测试.项目初始化的时候,symfony会自动建立一些基本的测试。
├── translations #
├── var # 缓存、数据、日志
│ ├── cache # 缓存目录 -d
│ └── log # 日志目录 存放symfony生成的应用程序的日志文件。 -d
├── vendor # 组件vendor目录是放第三方组件的目录,一般这个目录下的文件是通过composer来管理的。开发过程中不会动到这里面的代码(不排除调试)
├── .env # shell脚本,保存着一些配置(APP_ENV、doctrine、secret等)
├── .env.test #
├── .gitignore #
├── composerjson #
├── composer.lock #
├── phpunit.xml.dist #
├── README.md
└── symfony.lock
dev环境,symfony加载顺序
config/packages/*
config/packages/dev/*
config/services.yaml
config/services_dev.yaml
部分文件是安装相应的组件后添加的,比如annotations.yaml、doctrine.yaml、twig.yaml
symfony4 的命令行
// 执行以下命令查看项目指令
$ php bin/console
Symfony 4.3.3 (env: dev, debug: true)
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-e, --env=ENV The Environment name. [default: "dev"]
--no-debug Switches off debug mode.
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output,2 for more verbose output and 3 for debug
Available commands:
about Displays information about the current project
help Displays help for a command
list Lists commands
assets
assets:install Installs bundles web assets under a public directory
cache
cache:clear Clears the cache
cache:pool:clear Clears cache pools
cache:pool:delete Deletes an item from a cache pool
cache:pool:list List available cache pools
cache:pool:prune Prunes cache pools
cache:warmup Warms up an empty cache
config
config:dump-reference Dumps the default configuration for an extension
debug
debug:autowiring Lists classes/interfaces you can use for autowiring
debug:config Dumps the current configuration for an extension
debug:container Displays current services for an appli
cation
debug:event-dispatcher Displays configured listeners for an a
pplication
debug:form Displays form type information
debug:router Displays current routes for an application
debug:swiftmailer Displays current mailers for an application
debug:translation Displays translation messages informat
ion
debug:twig Shows a list of twig functions, filters, globals and tests
doctrine
doctrine:cache:clear-collection-region Clear a second-level cache collectionregion
doctrine:cache:clear-entity-region Clear a second-level cache entity region
doctrine:cache:clear-metadata Clears all metadata cache for an entity manager
doctrine:cache:clear-query Clears all query cache for an entity manager
doctrine:cache:clear-query-region Clear a second-level cache query region
doctrine:cache:clear-result Clears result cache for an entity manager
doctrine:cache:contains Check if a cache entry exists
doctrine:cache:delete Delete a cache entry
doctrine:cache:flush [doctrine:cache:clear] Flush a given cache
doctrine:cache:stats Get stats on a given cache provider
doctrine:database:create Creates the configured database
doctrine:database:drop Drops the configured database
doctrine:database:import Import SQL file(s) directly to Database.
doctrine:ensure-production-settings Verify that Doctrine is properly configured for a production environment
doctrine:generate:entities [generate:doctrine:entities] Generates entity classes and method stubs from your mapping information
doctrine:mapping:convert [orm:convert:mapping] Convert mapping information between supported formats
doctrine:mapping:import Imports mapping information from an existing database
doctrine:mapping:info
doctrine:migrations:diff [diff] Generate a migration by comparing your current database to your mapping information.
doctrine:migrations:dump-schema [dump-schema] Dump the schema for your database to a migration.
doctrine:migrations:execute [execute] Execute a single migration version up or down manually.
doctrine:migrations:generate [generate] Generate a blank migration class.
doctrine:migrations:latest [latest] Outputs the latest version number
doctrine:migrations:migrate [migrate] Execute a migration to a specified version or the latest available version.
doctrine:migrations:rollup [rollup] Rollup migrations by deleting all tracked versions and insert the one version that exists.
doctrine:migrations:status [status] View the status of a set of migrations.
doctrine:migrations:up-to-date [up-to-date] Tells you if your schema is up-to-date.
doctrine:migrations:version [version] Manually add and delete migration versions from the version table.
doctrine:query:dql Executes arbitrary DQL directly from the command line
doctrine:query:sql Executes arbitrary SQL directly from the command line.
doctrine:schema:create Executes (or dumps) the SQL needed togenerate the database schema
doctrine:schema:drop Executes (or dumps) the SQL needed todrop the current database schema
doctrine:schema:update Executes (or dumps) the SQL needed toupdate the database schema to match the current mapping metadata
doctrine:schema:validate Validate the mapping files
lint
lint:twig Lints a template and outputs encountered errors
lint:xliff Lints a XLIFF file and outputs encountered errors
lint:yaml Lints a file and outputs encountered errors
make
make:auth Creates a Guard authenticator of different flavors
make:command Creates a new console command class
make:controller Creates a new controller class
make:crud Creates CRUD for Doctrine entity class
make:entity Creates or updates a Doctrine entity c
lass, and optionally an API Platform resource
make:fixtures Creates a new class to load Doctrine f
ixtures
make:form Creates a new form class
make:functional-test Creates a new functional test class
make:migration Creates a new migration based on database changes
make:registration-form Creates a new registration form system
make:serializer:encoder Creates a new serializer encoder class
make:serializer:normalizer Creates a new serializer normalizer class
make:subscriber Creates a new event subscriber class
make:twig-extension Creates a new Twig extension class
make:unit-test Creates a new unit test class
make:user Creates a new security user class
make:validator Creates a new validator and constraint class
make:voter Creates a new security voter class
router
router:match Helps debug routes by simulating a path info match
security
security:encode-password Encodes a password.
server
server:dump Starts a dump server that collects and displays dumps in a single place
server:log Starts a log server that displays logs in real time
server:run Runs a local web server
server:start Starts a local web server in the background
server:status Outputs the status of the local web server
server:stop Stops the local web server that was started with the server:start command
swiftmailer
swiftmailer:email:send Send simple email message
swiftmailer:spool:send Sends emails from the spool
translation
translation:update Updates the translation file