📜 ⬆️ ⬇️

A bit about symfony with doctrine for Linux

Starting to learn symfony, first of all I looked at articles on Habré. There are translations that tell you how to make your symfony project, where the sandbox is taken as a basis. It was interesting for me to figure out how to install and configure symfony + doctrine with only the source code of the framework. I have a big project to do, so in this article I will tell you what I was able to meet.


0 step: General


"/ home / nutt / workspace / htdocs" - the folder where the project will be located and where apache is looking.

Step 1: Installation


Download and unpack the source in the folder with the project
/home/nutt/workspace/htdocs

After that go directly to the folder and create a project. After executing the command, symfony will create all the necessary folders.
nutt@nutt:~/workspace/htdocs$ sudo ./data/bin/symfony generate:project test

I am developing a project in ubuntu on VirtualBox, so you may not need the following adjustment. In order to be visible develop-panel (http: //localhost/frontend_dev.php/) need to be corrected in:
~/workspace/htdocs/web/frontend_dev.php

if (!in_array(@$_SERVER[ 'REMOTE_ADDR' ], array ( '[ IP], ' ::80')))

')
Next, you need to configure apache (/ etc / apache2 / sites-enabled / 000-default):
< VirtualHost [ IP ] :80 >
ServerName nutt.com
DocumentRoot /home/nutt/workspace/htdocs/web

php_admin_value register_globals Off

RewriteLog "/var/log/apache2/mod_rewrite.log"
RewriteLogLevel 2
Alias /sf /home/nutt/workspace/htdocs/data/web/sf
< Directory / home / nutt / workspace / htdocs / web >
Options Indexes FollowSymLinks MultiViews ExecCGI
Options All
AllowOverride All
Order allow,deny
Allow from all
</ Directory >
</ VirtualHost >


Step 2: Doctrine


Propel uses symfony by default. For my project, I had to switch to Doctrine (sfDoctrinePlugin). For this
you need to edit the ProjectConfiguration.class.php file in ~ / workspace / htdocs / config

It was:
public function setup()
{
$ this ->enablePlugins(array( 'sfDoctrinePlugin' ));
$ this ->disablePlugins(array( 'sfPropelPlugin' ));
}
It became:
public function setup()
{
$ this ->enablePlugins(array( 'sfDoctrinePlugin' ));
}


Remove from Propel config:
nutt@nutt:~/workspace/htdocs/config$ sudo rm propel.ini
nutt@nutt:~/workspace/htdocs/config$ sudo rm schema.yml


Add a doctrine connection:
nutt@nutt:~/workspace/htdocs$ sudo ./data/bin/symfony configure:database --name=doctrine -- class =sfDoctrineDatabase "mysql:host=localhost;dbname=test" root root


Step 3: Create Tables with Doctrine



Edit the schema.yml file in ~ / workspace / htdocs / config / doctrine / schema.yml
users:
columns:
name: { type: string (255), notnull: true , unique: true }


Generating classes:
nutt@nutt:~/workspace/htdocs$ ./data/bin/symfony doctrine:build-model


Build SQL queries:
nutt@nutt:~/workspace/htdocs$ ./data/bin/symfony doctrine:build-sql


Execute SQL:
nutt@nutt:~/workspace/htdocs$ ./data/bin/symfony doctrine:insert-sql


Questions:


  1. There is a table with three foreign keys for one ID. In Doctrine, I described them as follows:
    1. relations:
    2. Tblaccount:
    3. foreignAlias: tbltransaction
    4. local: intinaccountid
    5. foreign: intaccountid
    6. type: one
    7. foreignType: many
    8. Tblaccount:
    9. foreignAlias: tbltransaction
    10. local: intoutaccountid
    11. foreign: intaccountid
    12. type: one
    13. foreignType: many
    14. Tblaccount:
    15. foreignAlias: tbltransaction
    16. local: intfeeaccountid
    17. foreign: intaccountid
    18. type: one
    19. foreignType: many


    After doctrine: build-sql in SQL, only the last link is generated:
    1. ALTER TABLE tbltransaction ADD FOREIGN KEY (intfeeaccountid) REFERENCES tblaccount (intaccountid);

    How to make all foreign keys be created?

  2. I have the whole project and symfony itself is in the same folder. Is it correct? How do you locate the project?

Thank.

PS


For a long time I have been waiting for the last vote on getting an invite for a friend . I will be grateful.

Source: https://habr.com/ru/post/50642/


All Articles