Simple example with Symfony2

I read the Symfony2 documentation , but I donโ€™t quite understand (how to create a model, repository, configure doctrine.orm in config.yml and other simple things that are easy in sf 1). Therefore, I am looking for a small example that uses Symfony2. A very simple example (for example, a sandbox , but a bit more advanced) with a page listing the contents of the table with the ORM doctrine and editing / new page. I did not find anything on GitHub! The site documentation with a real example will be very useful! Thank you very much.

I continue to dive in sf2 ...

+4
source share
2 answers

Bundles Symfony2 is a valuable source of applications based on Symfony2 and third-party packages.

However, you should keep in mind that many of the projects you may discover are outdated, as Sf2 is still unstable and its API changes frequently.

Basically, all you have to do is:

  • Ensure that Doctrines packages are included in ApplicationKernel .
  • Make sure it is configured correctly:

     doctrine.dbal: driver: pdo_pgsql host: 127.0.0.1 user: root password: password dbname: my_database charset: utf8 doctrine.orm: mappings: MyApplicationBundle: ~ SomeThirdPartyBundle: ~ 
  • Create multiple objects.

  • Although you can use the Doctrine2 repositories, I am not a big fan of them. IMO is better off creating their own managers (they can use the original repositories) that will provide a transparent API. You do not need to identify your model layer as an ORM only. You can check out UserBundle by FriendsOfSymfony , as their approach is pretty good.

End use:

 $posts = $this->get('myapp.post_manager')->findRecentlyUsed(new \DateTime('-1 week')); return $this->render('MyApp:Post:list.html.twig', array( 'posts' => $posts )); 
+1
source

Symfony DIC and config have changed!

Now you should use sth, like this in your config.yml:

 doctrine: dbal: driver: pdo_pgsql host: 127.0.0.1 user: root password: password dbname: my_database charset: utf8 orm: mappings: MyApplicationBundle: ~ SomeThirdPartyBundle: ~ 
+1
source

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


All Articles