@@ -66,7 +66,7 @@ The "Random Number" Page
66
66
67
67
In this chapter, you'll develop an application that can generate random numbers.
68
68
When you're finished, the user will be able to get a random number between ``1 ``
69
- and the upper limit set with the URL:
69
+ and the upper limit set by the URL:
70
70
71
71
.. code-block :: text
72
72
@@ -98,15 +98,15 @@ A bundle is nothing more than a directory that houses everything related
98
98
to a specific feature, including PHP classes, configuration, and even stylesheets
99
99
and JavaScript files (see :ref: `page-creation-bundles `).
100
100
101
- To create a bundle called ``AcmeWebsiteBundle `` (a play bundle that you'll
101
+ To create a bundle called ``AcmeDemoBundle `` (a play bundle that you'll
102
102
build in this chapter), run the following command and follow the on-screen
103
103
instructions (use all of the default options):
104
104
105
105
.. code-block :: bash
106
106
107
- $ php app/console generate:bundle --namespace=Acme/WebsiteBundle --format=yml
107
+ $ php app/console generate:bundle --namespace=Acme/DemoBundle --format=yml
108
108
109
- Behind the scenes, a directory is created for the bundle at ``src/Acme/WebsiteBundle ``.
109
+ Behind the scenes, a directory is created for the bundle at ``src/Acme/DemoBundle ``.
110
110
A line is also automatically added to the ``app/AppKernel.php `` file so that
111
111
the bundle is registered with the kernel::
112
112
@@ -115,7 +115,7 @@ the bundle is registered with the kernel::
115
115
{
116
116
$bundles = array(
117
117
...,
118
- new Acme\WebsiteBundle\AcmeWebsiteBundle (),
118
+ new Acme\DemoBundle\AcmeDemoBundle (),
119
119
);
120
120
// ...
121
121
@@ -133,15 +133,15 @@ located at ``app/config/routing.yml``. Like all configuration in Symfony2,
133
133
you can also choose to use XML or PHP out of the box to configure routes.
134
134
135
135
If you look at the main routing file, you'll see that Symfony already added
136
- an entry when you generated the ``AcmeWebsiteBundle ``:
136
+ an entry when you generated the ``AcmeDemoBundle ``:
137
137
138
138
.. configuration-block ::
139
139
140
140
.. code-block :: yaml
141
141
142
142
# app/config/routing.yml
143
143
acme_website :
144
- resource : " @AcmeWebsiteBundle /Resources/config/routing.yml"
144
+ resource : " @AcmeDemoBundle /Resources/config/routing.yml"
145
145
prefix : /
146
146
147
147
.. code-block :: xml
@@ -153,7 +153,7 @@ an entry when you generated the ``AcmeWebsiteBundle``:
153
153
xsi : schemaLocation =" http://symfony.com/schema/routing
154
154
http://symfony.com/schema/routing/routing-1.0.xsd" >
155
155
156
- <import resource =" @AcmeWebsiteBundle /Resources/config/routing.xml"
156
+ <import resource =" @AcmeDemoBundle /Resources/config/routing.xml"
157
157
prefix =" /" />
158
158
</routes >
159
159
@@ -165,14 +165,14 @@ an entry when you generated the ``AcmeWebsiteBundle``:
165
165
166
166
$collection = new RouteCollection();
167
167
$collection->addCollection(
168
- $loader->import('@AcmeWebsiteBundle /Resources/config/routing.php'),
168
+ $loader->import('@AcmeDemoBundle /Resources/config/routing.php'),
169
169
'/'
170
170
);
171
171
172
172
return $collection;
173
173
174
174
This entry is pretty basic: it tells Symfony to load routing configuration
175
- from the ``Resources/config/routing.yml `` file that lives inside the ``AcmeWebsiteBundle ``.
175
+ from the ``Resources/config/routing.yml `` file that lives inside the ``AcmeDemoBundle ``.
176
176
This means that you place routing configuration directly in ``app/config/routing.yml ``
177
177
or organize your routes throughout your application, and import them from here.
178
178
@@ -183,34 +183,34 @@ the new route that defines the URL of the page that you're about to create:
183
183
184
184
.. code-block :: yaml
185
185
186
- # src/Acme/WebsiteBundle /Resources/config/routing.yml
186
+ # src/Acme/DemoBundle /Resources/config/routing.yml
187
187
random :
188
188
path : /random/{limit}
189
- defaults : { _controller: AcmeWebsiteBundle :Random:index }
189
+ defaults : { _controller: AcmeDemoBundle :Random:index }
190
190
191
191
.. code-block :: xml
192
192
193
- <!-- src/Acme/WebsiteBundle /Resources/config/routing.xml -->
193
+ <!-- src/Acme/DemoBundle /Resources/config/routing.xml -->
194
194
<?xml version =" 1.0" encoding =" UTF-8" ?>
195
195
<routes xmlns =" http://symfony.com/schema/routing"
196
196
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
197
197
xsi : schemaLocation =" http://symfony.com/schema/routing
198
198
http://symfony.com/schema/routing/routing-1.0.xsd" >
199
199
200
200
<route id =" random" path =" /random/{limit}" >
201
- <default key =" _controller" >AcmeWebsiteBundle :Random:index</default >
201
+ <default key =" _controller" >AcmeDemoBundle :Random:index</default >
202
202
</route >
203
203
</routes >
204
204
205
205
.. code-block :: php
206
206
207
- // src/Acme/WebsiteBundle /Resources/config/routing.php
207
+ // src/Acme/DemoBundle /Resources/config/routing.php
208
208
use Symfony\Component\Routing\RouteCollection;
209
209
use Symfony\Component\Routing\Route;
210
210
211
211
$collection = new RouteCollection();
212
212
$collection->add('random', new Route('/random/{limit}', array(
213
- '_controller' => 'AcmeWebsiteBundle :Random:index',
213
+ '_controller' => 'AcmeDemoBundle :Random:index',
214
214
)));
215
215
216
216
return $collection;
@@ -233,17 +233,17 @@ Step 2: Create the Controller
233
233
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
234
234
235
235
When a URL such as ``/random/10 `` is handled by the application, the ``random ``
236
- route is matched and the ``AcmeWebsiteBundle :Random:index `` controller is executed
236
+ route is matched and the ``AcmeDemoBundle :Random:index `` controller is executed
237
237
by the framework. The second step of the page-creation process is to create
238
238
that controller.
239
239
240
- The controller - ``AcmeWebsiteBundle :Random:index `` is the *logical * name of
240
+ The controller - ``AcmeDemoBundle :Random:index `` is the *logical * name of
241
241
the controller, and it maps to the ``indexAction `` method of a PHP class
242
- called ``Acme\WebsiteBundle \Controller\RandomController ``. Start by creating this
243
- file inside your ``AcmeWebsiteBundle ``::
242
+ called ``Acme\DemoBundle \Controller\RandomController ``. Start by creating this
243
+ file inside your ``AcmeDemoBundle ``::
244
244
245
- // src/Acme/WebsiteBundle /Controller/RandomController.php
246
- namespace Acme\WebsiteBundle \Controller;
245
+ // src/Acme/DemoBundle /Controller/RandomController.php
246
+ namespace Acme\DemoBundle \Controller;
247
247
248
248
class RandomController
249
249
{
@@ -258,8 +258,8 @@ object.
258
258
Create the ``indexAction `` method that Symfony will execute when the ``random ``
259
259
route is matched::
260
260
261
- // src/Acme/WebsiteBundle /Controller/RandomController.php
262
- namespace Acme\WebsiteBundle \Controller;
261
+ // src/Acme/DemoBundle /Controller/RandomController.php
262
+ namespace Acme\DemoBundle \Controller;
263
263
264
264
use Symfony\Component\HttpFoundation\Response;
265
265
@@ -319,8 +319,8 @@ of writing the HTML inside the controller, render a template instead:
319
319
.. code-block :: php
320
320
:linenos:
321
321
322
- // src/Acme/WebsiteBundle /Controller/RandomController.php
323
- namespace Acme\WebsiteBundle \Controller;
322
+ // src/Acme/DemoBundle /Controller/RandomController.php
323
+ namespace Acme\DemoBundle \Controller;
324
324
325
325
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
326
326
@@ -331,13 +331,13 @@ of writing the HTML inside the controller, render a template instead:
331
331
$number = rand(1, $limit);
332
332
333
333
return $this->render(
334
- 'AcmeWebsiteBundle :Random:index.html.twig',
334
+ 'AcmeDemoBundle :Random:index.html.twig',
335
335
array('number' => $number)
336
336
);
337
337
338
338
// render a PHP template instead
339
339
// return $this->render(
340
- // 'AcmeWebsiteBundle :Random:index.html.php',
340
+ // 'AcmeDemoBundle :Random:index.html.php',
341
341
// array('number' => $number)
342
342
// );
343
343
}
@@ -361,7 +361,7 @@ By default, Symfony2 supports two different templating languages: classic
361
361
PHP templates and the succinct but powerful `Twig `_ templates. Don't be
362
362
alarmed - you're free to choose either or even both in the same project.
363
363
10000
div>
364
- The controller renders the ``AcmeWebsiteBundle :Random:index.html.twig `` template,
364
+ The controller renders the ``AcmeDemoBundle :Random:index.html.twig `` template,
365
365
which uses the following naming convention:
366
366
367
367
**BundleName **:**ControllerName **:**TemplateName **
@@ -371,15 +371,15 @@ location using the following convention.
371
371
372
372
**/path/to/BundleName **/Resources/views/**ControllerName **/**TemplateName **
373
373
374
- In this case, ``AcmeWebsiteBundle `` is the bundle name, ``Random `` is the
374
+ In this case, ``AcmeDemoBundle `` is the bundle name, ``Random `` is the
375
375
controller, and ``index.html.twig `` the template:
376
376
377
377
.. configuration-block ::
378
378
379
379
.. code-block :: jinja
380
380
:linenos:
381
381
382
- {# src/Acme/WebsiteBundle /Resources/views/Random/index.html.twig #}
382
+ {# src/Acme/DemoBundle /Resources/views/Random/index.html.twig #}
383
383
{% extends '::base.html.twig' %}
384
384
385
385
{% block body %}
@@ -388,7 +388,7 @@ controller, and ``index.html.twig`` the template:
388
388
389
389
.. code-block :: html+php
390
390
391
- <!-- src/Acme/WebsiteBundle /Resources/views/Random/index.html.php -->
391
+ <!-- src/Acme/DemoBundle /Resources/views/Random/index.html.php -->
392
392
<?php $view->extend('::base.html.php') ?>
393
393
394
394
Number: <?php echo $view->escape($number) ?>
@@ -573,9 +573,9 @@ You'll learn more about each of these directories in later chapters.
573
573
.. code-block :: text
574
574
575
575
Class Name:
576
- Acme\WebsiteBundle \Controller\RandomController
576
+ Acme\DemoBundle \Controller\RandomController
577
577
Path:
578
- src/Acme/WebsiteBundle /Controller/RandomController.php
578
+ src/Acme/DemoBundle /Controller/RandomController.php
579
579
580
580
The Source (``src ``) Directory
581
581
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -725,7 +725,7 @@ Bundle Directory Structure
725
725
726
726
The directory structure of a bundle is simple and flexible. By default, the
727
727
bundle system follows a set of conventions that help to keep code consistent
728
- between all Symfony2 bundles. Take a look at ``AcmeWebsiteBundle ``, as it contains
728
+ between all Symfony2 bundles. Take a look at ``AcmeDemoBundle ``, as it contains
729
729
some of the most common elements of a bundle:
730
730
731
731
* ``Controller/ `` contains the controllers of the bundle (e.g. ``RandomController.php ``);
0 commit comments