The first step:
Composer Create-project Symfony/framework-standard-edition your project name;
After creating this prototype, I execute PHP bin/console Server:run, can run up;
So now you need to connect to the database: My database is PostgreSQL
Write a database creation script such as my
Create UserMyBlog withPassword'MyBlog' ;ALTER USERMyBlog withPASSWORD'MyBlog';Create DatabaseMyblog_dev withEncoding='UTF8' ;Create DatabaseMyblog_prod withEncoding='UTF8' ;Create DatabaseMyblog_test withEncoding='UTF8' ;Grant All Privileges on DatabaseMyblog_dev toMyBlog;Grant All Privileges on DatabaseMyblog_test toMyBlog;Grant All Privileges on DatabaseMyblog_prod toMyblog;\connect Myblog_dev;Create Schemaextensions;CreateExtension HstoreSchemaextensions;ALTER DATABASEMyblog_devSETSearch_path to"$User", Public, extensions;Alter DatabaseMyblog_dev owner toMyBlog;Alter Schema PublicOwner toMyBlog;Alter SchemaExtensions owner toMyBlog;GRANTUSAGE on SCHEMA Public toMyblog;\connect Myblog_prod;Create Schemaextensions;CreateExtension HstoreSchemaextensions;ALTER DATABASEMyblog_devSETSearch_path to"$User", Public, extensions;Alter DatabaseMyblog_dev owner toMyBlog;Alter Schema PublicOwner toMyBlog;Alter SchemaExtensions owner toMyBlog;GRANTUSAGE on SCHEMA Public toMyblog;\connect myblog_test;Create Schemaextensions;CreateExtension HstoreSchemaextensions;ALTER DATABASEMyblog_devSETSearch_path to"$User", Public, extensions;Alter DatabaseMyblog_dev owner toMyBlog;Alter Schema PublicOwner toMyBlog;Alter SchemaExtensions owner toMyBlog;GRANTUSAGE on SCHEMA Public toMyBlog;
View Code
Create a database based on a script.
The second step, let your program this prototype program to connect to the database:
Find Config.yml
Copy code:
# Doctrine ConfigurationDoctrine: dbal: driver: %database_driver% host: %database_host% port: %database_port% dbname: %database_name% user: %database_user% password:%database_password% CharSet: UTF8
View Code
Find Parameters.yml and Parameters.yml.dist.
Connect your database name (config-like):
# This file is auto-generated during the composer installparameters: database_driver: pdo_ Pgsql database_host: 127.0.0.1 database_portnull database_name: Database name database_user: database user name Database_password: database Password mailer_transport : SMTP mailer_host: 127.0.0.1 mailer_user: mailer_password : Secret: Thistokenisnotsosecretchangeit
View Code
This is connected to the database;
-----------------------------------------------
The third step is to start writing bundles according to your business needs:
Note: The true meaning of bundles is that it exists as an independent component of software that can be reused. If Userbundle cannot be used "as is" in another Symfony program, it should not be a bundle. In addition, if Invoicebundle relies on productbundle, there is no need to divide them into two bundles.
Here are the commands for wearing bundles: I'm not going to create a new bundle here.
PHP bin/console generate:bundle--namespace=appbundle--dir=src--format=annotation--no-interaction
Join me in writing a blog site with Symfony;