From 8e26ed294910c5141c28993a145b2c4bcdd37e59 Mon Sep 17 00:00:00 2001 From: ButenkoD Date: Wed, 6 Nov 2013 13:48:31 +0200 Subject: [PATCH 1/4] Local host mapped to app_dev.php --- web/.htaccess | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/.htaccess b/web/.htaccess index 0c5f37d..d0c145b 100755 --- a/web/.htaccess +++ b/web/.htaccess @@ -3,7 +3,7 @@ # mod_rewrite). Additionally, this reduces the matching process for the # start page (path "/") because otherwise Apache will apply the rewriting rules # to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl). -DirectoryIndex app.php +DirectoryIndex app_dev.php RewriteEngine On @@ -38,7 +38,7 @@ DirectoryIndex app.php RewriteRule .? - [L] # Rewrite all other queries to the front controller. - RewriteRule .? %{ENV:BASE}/app.php [L] + RewriteRule .? %{ENV:BASE}/app_dev.php [L] @@ -46,7 +46,7 @@ DirectoryIndex app.php # When mod_rewrite is not available, we instruct a temporary redirect of # the start page to the front controller explicitly so that the website # and the generated links can still be used. - RedirectMatch 302 ^/$ /app.php/ + RedirectMatch 302 ^/$ /app_dev.php/ # RedirectTemp cannot be used instead From 418b6af1ea899f6e1dc013ea040df5b678b635b3 Mon Sep 17 00:00:00 2001 From: ButenkoD Date: Wed, 6 Nov 2013 14:17:09 +0200 Subject: [PATCH 2/4] My routing included in routing_dev.yml, my routing and first action of MyController are created --- app/config/routing_dev.yml | 4 +++ .../DemoBundle/Controller/MyController.php | 27 +++++++++++++++++++ .../DemoBundle/Resources/config/myrouting.yml | 11 ++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/Acme/DemoBundle/Controller/MyController.php create mode 100755 src/Acme/DemoBundle/Resources/config/myrouting.yml diff --git a/app/config/routing_dev.yml b/app/config/routing_dev.yml index c45f361..d0d75fc 100755 --- a/app/config/routing_dev.yml +++ b/app/config/routing_dev.yml @@ -16,3 +16,7 @@ _main: # AcmeDemoBundle routes (to be removed) _acme_demo: resource: "@AcmeDemoBundle/Resources/config/routing.yml" + +# Including my routes resource to routing_dev.yml +myrouting: + resource: "@AcmeDemoBundle/Resources/config/myrouting.yml" diff --git a/src/Acme/DemoBundle/Controller/MyController.php b/src/Acme/DemoBundle/Controller/MyController.php new file mode 100644 index 0000000..ba7a18c --- /dev/null +++ b/src/Acme/DemoBundle/Controller/MyController.php @@ -0,0 +1,27 @@ +render('AcmeDemoBundle:Welcome:index.html.twig'); + } + +} \ No newline at end of file diff --git a/src/Acme/DemoBundle/Resources/config/myrouting.yml b/src/Acme/DemoBundle/Resources/config/myrouting.yml new file mode 100755 index 0000000..add8801 --- /dev/null +++ b/src/Acme/DemoBundle/Resources/config/myrouting.yml @@ -0,0 +1,11 @@ +simple_response: + pattern: /1/{name} + defaults: { _controller: AcmeDemoBundle:My:first, name: "noob :)" } + +simple_template: + pattern: /2 + defaults: { _controller: AcmeDemoBundle:My:second } + +extending_response: + pattern: /3 + defaults: { _controller: AcmeDemoBundle:My:third } From 1f3f8eb06f3044ce6939b0bd52e4e46974ccdcf4 Mon Sep 17 00:00:00 2001 From: ButenkoD Date: Wed, 6 Nov 2013 14:34:31 +0200 Subject: [PATCH 3/4] The 2nd action added to MyController --- src/Acme/DemoBundle/Controller/MyController.php | 14 ++++++++++++-- .../views/SimpleTemplate/simple.html.twig | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100755 src/Acme/DemoBundle/Resources/views/SimpleTemplate/simple.html.twig diff --git a/src/Acme/DemoBundle/Controller/MyController.php b/src/Acme/DemoBundle/Controller/MyController.php index ba7a18c..e4e1ecc 100644 --- a/src/Acme/DemoBundle/Controller/MyController.php +++ b/src/Acme/DemoBundle/Controller/MyController.php @@ -9,11 +9,12 @@ namespace Acme\DemoBundle\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response; -class MyController { - +class MyController extends Controller +{ public function firstAction($name) { /* @@ -24,4 +25,13 @@ public function firstAction($name) return new Response("Hello, ".$name);#$this->render('AcmeDemoBundle:Welcome:index.html.twig'); } + public function secondAction() + { + /* + * The action's view can be rendered using render() method + * or @Template annotation as demonstrated in DemoController. + * + */ + return $this->render('AcmeDemoBundle:SimpleTemplate:simple.html.twig'); + } } \ No newline at end of file diff --git a/src/Acme/DemoBundle/Resources/views/SimpleTemplate/simple.html.twig b/src/Acme/DemoBundle/Resources/views/SimpleTemplate/simple.html.twig new file mode 100755 index 0000000..5edcf44 --- /dev/null +++ b/src/Acme/DemoBundle/Resources/views/SimpleTemplate/simple.html.twig @@ -0,0 +1,16 @@ + + + + + Rendered simple template + + + + + +

Simple html. Result of the 2nd action in advanced controller, which returns simple template

+ + + \ No newline at end of file From 240789124a46565668f89f6253e7fdd52b501dfd Mon Sep 17 00:00:00 2001 From: ButenkoD Date: Wed, 6 Nov 2013 14:54:25 +0200 Subject: [PATCH 4/4] The 3rd action added to MyController --- .../DemoBundle/Controller/MyController.php | 10 +++++ .../ExtendingTemplate/extending.html.twig | 41 +++++++++++++++++++ .../views/SimpleTemplate/simple.html.twig | 5 ++- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100755 src/Acme/DemoBundle/Resources/views/ExtendingTemplate/extending.html.twig diff --git a/src/Acme/DemoBundle/Controller/MyController.php b/src/Acme/DemoBundle/Controller/MyController.php index e4e1ecc..6199d41 100644 --- a/src/Acme/DemoBundle/Controller/MyController.php +++ b/src/Acme/DemoBundle/Controller/MyController.php @@ -34,4 +34,14 @@ public function secondAction() */ return $this->render('AcmeDemoBundle:SimpleTemplate:simple.html.twig'); } + + public function thirdAction() + { + /* + * The action's view can be rendered using render() method + * or @Template annotation as demonstrated in DemoController. + * + */ + return $this->render('AcmeDemoBundle:ExtendingTemplate:extending.html.twig'); + } } \ No newline at end of file diff --git a/src/Acme/DemoBundle/Resources/views/ExtendingTemplate/extending.html.twig b/src/Acme/DemoBundle/Resources/views/ExtendingTemplate/extending.html.twig new file mode 100755 index 0000000..243ae70 --- /dev/null +++ b/src/Acme/DemoBundle/Resources/views/ExtendingTemplate/extending.html.twig @@ -0,0 +1,41 @@ +{% extends "TwigBundle::layout.html.twig" %} + +{% block head %} + + +{% endblock %} + +{% block title 'Rendered template that extends base template' %} + +{% block body %} + {% for flashMessage in app.session.flashbag.get('notice') %} +
+ Notice: {{ flashMessage }} +
+ {% endfor %} + + {% block content_header %} + + +
+ {% endblock %} + +
+ {% block content %} +

Result of the 3nd action in advanced controller, + which returns rendered template + that extends base template

+ {% endblock %} +
+ + {% if code is defined %} +

Code behind this page

+
+
{{ code|raw }}
+
+ {% endif %} +{% endblock %} diff --git a/src/Acme/DemoBundle/Resources/views/SimpleTemplate/simple.html.twig b/src/Acme/DemoBundle/Resources/views/SimpleTemplate/simple.html.twig index 5edcf44..412e0f0 100755 --- a/src/Acme/DemoBundle/Resources/views/SimpleTemplate/simple.html.twig +++ b/src/Acme/DemoBundle/Resources/views/SimpleTemplate/simple.html.twig @@ -10,7 +10,10 @@ -

Simple html. Result of the 2nd action in advanced controller, which returns simple template

+

+ Simple html. Result of the 2nd action in advanced controller, + which returns rendered simple template +

\ No newline at end of file