More Related Content Similar to Speed up your developments with Symfony2 Similar to Speed up your developments with Symfony2 (20) Speed up your developments with Symfony25. … and a full-stackframeworkbased on those components 6. Application bundles Third party bundles The Symfony2 stack Bridges Third party libraries Core Bundles Standalone Components 7. « A Bundleis a directory that has a well-defined structure and can host anythingfrom classes to controllers and web resources. » 30. <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title> {%blocktitle%}Welcome!{%endblock%} </title> <link rel="shortcut icon" href="{{asset('favicon.ico') }}" /> </head> <body> {%blockbody%}{%endblock%} </body> </html> base.html.twig 34. classDefaultControllerextends Controller { /** * @Route( * "/{year}/talk/{month}/{day}/{slug}", * requirements={ * "year"="{4}", * "month"="{2}", * "day"="{2}" * } * ) * @Template() */ public functionshowAction($slug, $day, $month, $year) { // ... } } 35. Doctrine ParameterConverter Convertsrequestsparameters to a Doctrine entity. classDefaultControllerextends Controller { /** * @Route("/talk/{id}") * @ParamConverter("talk", class="SensioConferenceBundle:Talk") * @Template() */ public functionshowAction(Talk $talk) { returnarray('talk'=> $talk); } } 37. The Web DebugToolbar Memory Queries Recorded logs Timers Currentenvironment Currentresponse Symfony2 version PHP environment 59. useSensioundleodoBundlentityask; useSensioundleodoBundleormaskType; public functionnewAction() { $task =newTask(); $task->setName('Write a blog post'); $task->setDueDate(new ateTime('tomorrow')); $request = $this->getRequest(); $form = $this->createForm(newTaskType(), $task); if ($request->getMethod() =='POST') { $form->bindRequest($request); if ($form->isValid()) { // save the task to the database... return $this->redirect($this->generateUrl('success')); } } } 63. FunctionalTesting classDefaultControllerTestextendsWebTestCase { public functiontestIndex() { $client =static::createClient(); $crawler = $client->request('GET', '/schedule'); $this->assertTrue( $crawler->filter('html:contains("Fabien")')->count() >0 ); $response = $client->getResponse(); $this->assertTrue($response->headers->has('expires')); } } 66. Expiration – Expires Header Field classDefaultControllerextends Controller { /** * @Route("/schedule") * @Template * @Cache(expires="tomorrow") */ public functionindexAction() { $title='ConferencesSchedule'; returnarray('title'=> $title); } } 67. Expiration – Cache-Control Header Field classDefaultControllerextends Controller { /** * @Route("/schedule") * @Template * @Cache(maxage="20") */ public functionindexAction() { $title='ConferencesSchedule'; returnarray('title'=> $title); } } 79. <?xml version="1.0"?> <xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"> <file source-language="en" datatype="plaintext" original="file.ext"> <body> <trans-unit id="1"> <source>Symfony2 isgreat</source> <target>J'aime Symfony2</target> </trans-unit> <trans-unit id="2"> <source>My name is %name%!</source> <target>Je m'appelle %name% !</target> </trans-unit> </body> </file> </xliff> 80. Translating Messages FromTwig {%setmessage = 'Symfony2 isgreat'%} {{message|trans}} {%setmessage = 'Mynameis %name%!'%} {{message|trans({'%name%': 'Hugo'}, "hello") }}