We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this questionI read the Symfony2 documentation but i do not quite understand (how to create model, repository, configure doctrine.orm
in config.yml
and other simple stuffs which are easy in sf 1). So i search a small example which use Symfony2. An very sim开发者_StackOverflow中文版ple example (like the sandbox but little more advanced) with a page which list the content of a table with doctrine ORM and an edit/new page. I don't find nothing on GitHub! Website documentation with real example will be very helpful!
Thank you very much...
I continue my dive into sf2...
Symfony2 Bundles is a valuable source of Symfony2-based applications and 3rd-party bundles.
However, you should keep in mind that lots of project you can find out there is out-dated as Sf2 is still not stable and its API is changed quite often.
Basically, all you have to do is:
- Ensure that Doctrines' bundles are enabled in your
ApplicationKernel
. Make sure it's configured properly:
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 some entities.
- Although you could use Doctrine2 repositories I'm not a big fan of them. IMO it's better to create your own managers (they can use original repositories) that will provide a transparent API. You shouldn't identify your model layer as ORM only. You could check out UserBundle by FriendsOfSymfony as their approach is pretty good.
Final usage:
$posts = $this->get('myapp.post_manager')->findRecentlyUsed(new \DateTime('-1 week'));
return $this->render('MyApp:Post:list.html.twig', array(
'posts' => $posts
));
Symfony DIC and config has changed!
You should now 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: ~
精彩评论