Symfony based code 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 = mysql

propel.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 = false

propel.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

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值