@@ -27,13 +27,13 @@ persisted to the database. Writing in flat PHP is quick and dirty:
27
27
28
28
<?php
29
29
// index.php
30
-
31
30
$link = mysql_connect('localhost', 'myuser', 'mypassword');
32
31
mysql_select_db('blog_db', $link);
33
32
34
33
$result = mysql_query('SELECT id, title FROM post', $link);
35
34
?>
36
35
36
+ <!doctype html>
37
37
<html>
38
38
<head>
39
39
<title>List of Posts</title>
@@ -54,6 +54,7 @@ persisted to the database. Writing in flat PHP is quick and dirty:
54
54
55
55
<?php
56
56
mysql_close($link);
57
+ ?>
57
58
58
59
That's quick to write, fast to execute, and, as your app grows, impossible
59
60
to maintain. There are several problems that need to be addressed:
@@ -85,7 +86,6 @@ the code that prepares the HTML "presentation":
85
86
86
87
<?php
87
88
// index.php
88
-
89
89
$link = mysql_connect('localhost', 'myuser', 'mypassword');
90
90
mysql_select_db('blog_db', $link);
91
91
@@ -106,6 +106,7 @@ is primarily an HTML file that uses a template-like PHP syntax:
106
106
107
107
.. code-block :: html+php
108
108
109
+ <!doctype html>
109
110
<html>
110
111
<head>
111
112
<title>List of Posts</title>
@@ -146,7 +147,6 @@ of the application are isolated in a new file called ``model.php``:
146
147
147
148
<?php
148
149
// model.php
149
-
150
150
function open_database_connection()
151
151
{
152
152
$link = mysql_connect('localhost', 'myuser', 'mypassword');
@@ -543,8 +543,8 @@ them for you. Here's the same sample application, now built in Symfony2:
543
543
544
544
<?php
545
545
// src/Acme/BlogBundle/Controller/BlogController.php
546
-
547
546
namespace Acme\B logBundle\C ontroller;
547
+
548
548
use Symfony\B undle\F rameworkBundle\C ontroller\C ontroller;
549
549
550
550
class BlogController extends Controller
@@ -602,6 +602,7 @@ The layout is nearly identical:
602
602
.. code-block :: html+php
603
603
604
604
<!-- app/Resources/views/layout.html.php -->
605
+ <!doctype html>
605
606
<html>
606
607
<head>
607
608
<title><?php echo $view['slots']->output('title', 'Default title') ?></title>
@@ -699,7 +700,6 @@ for example, the list template written in Twig:
699
700
.. code-block :: html+jinja
700
701
701
702
{# src/Acme/BlogBundle/Resources/views/Blog/list.html.twig #}
702
-
703
703
{% extends "::layout.html.twig" %}
704
704
{% block title %}List of Posts{% endblock %}
705
705
@@ -708,7 +708,7 @@ for example, the list template written in Twig:
708
708
<ul>
709
709
{% for post in posts %}
710
710
<li>
711
- <a href="{{ path('blog_show', { 'id': post.id }) }}">
711
+ <a href="{{ path('blog_show', {'id': post.id}) }}">
712
712
{{ post.title }}
713
713
</a>
714
714
</li>
@@ -721,7 +721,7 @@ The corresponding ``layout.html.twig`` template is also easier to write:
721
721
.. code-block :: html+jinja
722
722
723
723
{# app/Resources/views/layout.html.twig #}
724
-
724
+ <!doctype html>
725
725
<html>
726
726
<head>
727
727
<title>{% block title %}Default title{% endblock %}</title>
0 commit comments