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