跟我一起用Symfony写一个博客网站;
Posted 01coding.com
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了跟我一起用Symfony写一个博客网站;相关的知识,希望对你有一定的参考价值。
第一步:
composer create-project symfony/framework-standard-edition 你的项目名;
创建完这个原型,我执行php bin/console server:run,可以跑起来;
那么此刻你需要连接数据库了:我的数据库是PostgreSql
写一个数据库创建脚本例如我的
create user myblog with password ‘myblog‘ ; ALTER USER myblog WITH PASSWORD ‘myblog‘; create database myblog_dev with encoding=‘utf8‘ ; create database myblog_prod with encoding=‘utf8‘ ; create database myblog_test with encoding=‘utf8‘ ; grant all privileges on database myblog_dev to myblog ; grant all privileges on database myblog_test to myblog; grant all privileges on database myblog_prod to myblog; \connect myblog_dev; create schema extensions; create extension hstore schema extensions; ALTER DATABASE myblog_dev SET search_path to "$user",public,extensions; alter database myblog_dev owner to myblog; alter schema public owner to myblog; alter schema extensions owner to myblog; GRANT USAGE ON SCHEMA public to myblog; \connect myblog_prod; create schema extensions; create extension hstore schema extensions; ALTER DATABASE myblog_dev SET search_path to "$user",public,extensions; alter database myblog_dev owner to myblog; alter schema public owner to myblog; alter schema extensions owner to myblog; GRANT USAGE ON SCHEMA public to myblog; \connect myblog_test; create schema extensions; create extension hstore schema extensions; ALTER DATABASE myblog_dev SET search_path to "$user",public,extensions; alter database myblog_dev owner to myblog; alter schema public owner to myblog; alter schema extensions owner to myblog; GRANT USAGE ON SCHEMA public to myblog;
根据脚本创建数据库。
第二步,让你的程序这个原型程序连接数据库:
找到config.yml
复制代码:
# Doctrine Configuration doctrine: dbal: driver: %database_driver% host: %database_host% port: %database_port% dbname: %database_name% user: %database_user% password: %database_password% charset: UTF8
找到parameters.yml和parameters.yml.dist
连接你的数据库名字(配置一样的):
# This file is auto-generated during the composer install parameters: database_driver: pdo_pgsql database_host: 127.0.0.1 database_port: null database_name: 数据库名字 database_user: 数据库用户名 database_password: 数据库密码 mailer_transport: smtp mailer_host: 127.0.0.1 mailer_user: mailer_password: secret: ThisTokenIsNotSoSecretChangeIt
这样就连上数据库了;
-----------------------------------------------
第三步,根据业务需求开始写Bundle:
注:bundle的真义在于,它是作为软件的一个“可被复用”的独立构成而存在。如果UserBundle不能“原封不动地”使用在别的Symfony程序中,它不应该成为bundle。另外,如果InvoiceBundle依赖于ProductBundle,那便没有任何必要将它们分成两个bundle。
以下是穿件Bundle的命令:在这里我不打算创建新Bundle
php bin/console generate:bundle --namespace=AppBundle --dir=src --format=annotation --no-interaction
以上是关于跟我一起用Symfony写一个博客网站;的主要内容,如果未能解决你的问题,请参考以下文章