Mysql connection configuration, schema and model generation.
In this article, you’ll find all that you need to configure your symfony installation for connect to a mysql database.
In addition, I will explain:
- How to configure propel to use InnoDB, a particular configuration quite difficult to find in documentation.
- How to extend or use and modify auto generated administration code.
Good reading.
Mauro Casula.
Symfony-Framework.com
1. Modify propel.ini <project>/config/propel.ini
Note the line “propel.mysql.tableType = InnoDB” this particular line say propel to use InnoDb as engine.
If you don’t use this line, you can forget the automatic recognition of foreign key in administration generator.
propel.targetPackage = lib.model
propel.packageObjectModel = true
propel.project = sf_sandbox
propel.database = mysqlpropel.database.createUrl = mysql://localhost/
propel.database.url = mysql://USERNAME:PASSWORD@localhost/DABASENAME#This line do that propel use InnoDB as database Engine
propel.mysql.tableType = InnoDB
propel.addGenericAccessors = true
propel.addGenericMutators = true
propel.addTimeStamp = falsepropel.schema.validate = false
…..
2. Modify database.yml
<project>/config/database.yml
all:
propel:
class: sfPropelDatabase
param:
phptype: mysql
hostspec: localhost
database: DATABASENAME
username: USERNAME
password: PASSWORD
3. Clear cache:
> symfony cc
4. Create the schema.yml with propel tools
> symfony propel-build-schema
This istruction create this file: <project>/config/schema.yml
5. Create the model
For create the model classes:
> symfony propel-build-model
6. Check all generating administrative pages
If doesnt exist, create a backend application:
> symfony init-app backend
Create the administrative action:
> symfony propel-init-admin applicationName moduleName modelName
( this command create the directory: <project>/apps/applicationName/modules/moduleName )
And inside this folder:
<project>/apps/applicationName/modules/moduleName
- actions
- actions.class.php
- templeates
- config
- generator.yml
- validate
NOTICE:
- If the database table is named Customer, the relative class will be named Customers. (Take attention with uppercase )
- The model classes are inside the <project>/lib/model directory.
- The administative actions are inside of cache directory: <project>\cache\backend\dev\modules\autoSfModuleName
If you want to extend the administrator functionality, you can add your actions in actions.class.php.
Otherwise, another option is to copy all the cache templeates and actions.class.php in your module folder ( to <project>/apps/nombreApplicacion/modules/nombreModulo/) and change inside actions.class.php file copied from cache
autoNombreModuloActions extends sfActions
with this:
NombreModuloActions extends sfActions
12 Responses to “Mysql connection configuration, schema and model generation.”
You can leave a response, or trackback from your own site.
Joshua
Said this at 4:57pm:Thanks Mauro.. i was just searching that!
Joshua.
Santi
Said this at 4:29pm:You are the best Mauro!!
Thanks a lot, this is gonna be very usefull for me.
Go on, and don’t give up.
Santi.
Bulletin News
Said this at 12:21am:Exciting review on onnection configuration, schema and model generation. | Symfony-framework.com! I love this articles!
ia64
Said this at 10:47am:I’m seeing issues with propel-build-schema/model that will not automatically “connect” product to an existing product_i18n table. is this a known bug?
Roantee
Said this at 4:39pm:Pretty nice blog , wants to see much more on it!
Natassia Malthe
Said this at 9:35am:Hello webmaster…Man i just love your blog, keep the cool posts about connection configuration, schema and model generation. | Symfony-framework.com comin..
holy Thursday .
Bulletin News
Said this at 10:23pm:Outstanding view discussing onnection configuration, schema and model generation. | Symfony-framework.com! I enjoy your view!
Gordon
Said this at 12:02am:I found this by googling. Propel’s documentation is not very thorough on the matter and you have saved me a lot of trouble. Thank you!
Natassia Malthe
Said this at 1:24am:Hi…I found your site via Yahoo! when i was searching for natassia malthe, and this post regarding onnection configuration, schema and model generation. | Symfony-framework.com really sounds very interesting to me.. Thanks.
Natassia Malthe
Said this at 1:32am:Hi…I found your site via Yahoo! when i was searching for natissia malthe, and this post regarding onnection configuration, schema and model generation. | Symfony-framework.com really sounds very interesting to me.. Thanks.
Natassia Malthe
Said this at 3:54am:Hi…I found your site via Yahoo! when i was searching for natassia malth, and this post regarding onnection configuration, schema and model generation. | Symfony-framework.com really sounds very interesting to me.. Thanks.
Natassia Malthe
Said this at 3:55am:Hi there…I Googled for model, but found your page about onnection configuration, schema and model generation. | Symfony-framework.com…and have to say thanks. nice read.