README 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. Propel Bundle
  2. =============
  3. This is a (work in progress) implementation of Propel in Symfony 2.
  4. Currently supports:
  5. * Generation of model classes based on an XML schema (not YAML) placed under `BundleName/Resources/*schema.xml`.
  6. * Runtime autoloading of Propel and generated classes
  7. * Propel runtime initialization through the XML configuration.
  8. Installation
  9. ------------
  10. * Checkout Propel and Phing in the src/vendor/ directory
  11. > cd sandbox/src/vendor
  12. > svn checkout http://svn.propelorm.org/branches/1.5 propel
  13. > svn checkout http://phing.mirror.svn.symfony-project.com/tags/2.3.3/classes/phing phing
  14. Sample Configuration
  15. --------------------
  16. ### Project configuration
  17. # in sandbox/hello/config/config.yml
  18. propel.config:
  19. path: %kernel.root_dir%/../src/vendor/propel
  20. phing_path: %kernel.root_dir%/../src/vendor/phing
  21. propel.dbal:
  22. driver: mysql
  23. user: root
  24. password: null
  25. dsn: mysql:host=localhost;dbname=test
  26. options: {}
  27. # default_connection: default
  28. # connections:
  29. # default:
  30. # driver: mysql
  31. # user: root
  32. # password: null
  33. # dsn: mysql:host=localhost;dbname=test
  34. # options: {}
  35. ### Sample Schema
  36. Place the following schema in src/Application/HelloBundle/Resources/config/schema.xml:
  37. <?xml version="1.0" encoding="UTF-8"?>
  38. <database name="default" namespace="Application\HelloBundle\Model" defaultIdMethod="native">
  39. <table name="book">
  40. <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
  41. <column name="title" type="varchar" primaryString="1" size="100" />
  42. <column name="ISBN" type="varchar" size="20" />
  43. <column name="author_id" type="integer" />
  44. <foreign-key foreignTable="author">
  45. <reference local="author_id" foreign="id" />
  46. </foreign-key>
  47. </table>
  48. <table name="author">
  49. <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
  50. <column name="first_name" type="varchar" size="100" />
  51. <column name="last_name" type="varchar" size="100" />
  52. </table>
  53. </database>
  54. ### Build Process
  55. Call the application console with the `propel:build` task:
  56. > ./hello/console propel:build --classes
  57. ### Use The Model Classes
  58. Use the Model classes as any other class in Symfony. Just use the correct namespace, and Symfony will autoload them:
  59. class HelloController extends Controller
  60. {
  61. public function indexAction($name)
  62. {
  63. $author = new \Application\HelloBundle\Model\Author();
  64. $author->setFirstName($name);
  65. $author->save();
  66. return $this->render('HelloBundle:Hello:index', array('name' => $name, 'author' => $author));
  67. }
  68. }
  69. Known Problems
  70. --------------
  71. Your application must not be in a path including dots in directory names (i.e. '/Users/me/symfony/2.0/sandbox/' fails).