-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Changing some uses of let's #1968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,15 +22,13 @@ HTTP response. | |
Symfony2 follows this philosophy and provides you with tools and conventions | ||
to keep your application organized as it grows in users and complexity. | ||
|
||
Sounds simple enough? Let's dive in! | ||
|
||
.. index:: | ||
single: Page creation; Example | ||
|
||
The "Hello Symfony!" Page | ||
------------------------- | ||
|
||
Let's start with a spin off of the classic "Hello World!" application. When | ||
To begin with, a spin off of the classic "Hello World!" application. When | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about:
|
||
you're finished, the user will be able to get a personal greeting (e.g. "Hello Symfony") | ||
by going to the following URL: | ||
|
||
|
@@ -347,7 +345,7 @@ controller, and ``index.html.twig`` the template: | |
|
||
Hello <?php echo $view->escape($name) ?>! | ||
|
||
Let's step through the Twig template line-by-line: | ||
Stepping through the Twig template line-by-line: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
* *line 2*: The ``extends`` token defines a parent template. The template | ||
explicitly defines a layout file inside of which it will be placed. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
Databases and Propel | ||
==================== | ||
|
||
Let's face it, one of the most common and challenging tasks for any application | ||
One of the most common and challenging tasks for any application | ||
involves persisting and reading information to and from a database. Symfony2 | ||
does not come integrated with any ORMs but the Propel integration is easy. | ||
To get started, read `Working With Symfony2`_. | ||
|
@@ -18,8 +18,8 @@ persist it to the database and fetch it back out. | |
.. sidebar:: Code along with the example | ||
|
||
If you want to follow along with the example in this chapter, create an | ||
``AcmeStoreBundle`` via: | ||
``AcmeStoreBundle`` via: | ||
|
||
.. code-block:: bash | ||
|
||
$ php app/console generate:bundle --namespace=Acme/StoreBundle | ||
|
@@ -171,19 +171,19 @@ Fetching Objects from the Database | |
Fetching an object back from the database is even easier. For example, suppose | ||
you've configured a route to display a specific ``Product`` based on its ``id`` | ||
value:: | ||
|
||
// ... | ||
use Acme\StoreBundle\Model\ProductQuery; | ||
|
||
public function showAction($id) | ||
{ | ||
$product = ProductQuery::create() | ||
->findPk($id); | ||
|
||
if (!$product) { | ||
throw $this->createNotFoundException('No product found for id '.$id); | ||
} | ||
|
||
// ... do something, like pass the $product object into a template | ||
} | ||
|
||
|
@@ -192,22 +192,22 @@ Updating an Object | |
|
||
Once you've fetched an object from Propel, updating it is easy. Suppose you | ||
have a route that maps a product id to an update action in a controller:: | ||
|
||
// ... | ||
use Acme\StoreBundle\Model\ProductQuery; | ||
|
||
public function updateAction($id) | ||
{ | ||
$product = ProductQuery::create() | ||
->findPk($id); | ||
|
||
if (!$product) { | ||
throw $this->createNotFoundException('No product found for id '.$id); | ||
} | ||
|
||
$product->setName('New product name!'); | ||
$product->save(); | ||
|
||
return $this->redirect($this->generateUrl('homepage')); | ||
} | ||
|
||
|
@@ -227,12 +227,12 @@ method on the object:: | |
|
||
Querying for Objects | ||
-------------------- | ||
|
||
Propel provides generated ``Query`` classes to run both basic and complex queries | ||
without any work:: | ||
|
||
\Acme\StoreBundle\Model\ProductQuery::create()->findPk($id); | ||
|
||
\Acme\StoreBundle\Model\ProductQuery::create() | ||
->filterByName('Foo') | ||
->findOne(); | ||
|
@@ -287,13 +287,13 @@ Start by adding the ``category`` definition in your ``schema.xml``: | |
<column name="name" type="varchar" primaryString="true" size="100" /> | ||
<column name="price" type="decimal" /> | ||
<column name="description" type="longvarchar" /> | ||
|
||
<column name="category_id" type="integer" /> | ||
<foreign-key foreignTable="category"> | ||
<reference local="category_id" foreign="id" /> | ||
</foreign-key> | ||
</table> | ||
|
||
<table name="category"> | ||
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" /> | ||
<column name="name" type="varchar" primaryString="true" size="100" /> | ||
|
@@ -320,29 +320,29 @@ Your database has been updated, you can continue to write your application. | |
Saving Related Objects | ||
~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Now, let's see the code in action. Imagine you're inside a controller:: | ||
Now, for the code in action. Imagine you're inside a controller:: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about:
|
||
|
||
// ... | ||
use Acme\StoreBundle\Model\Category; | ||
use Acme\StoreBundle\Model\Product; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class DefaultController extends Controller | ||
{ | ||
public function createProductAction() | ||
{ | ||
$category = new Category(); | ||
$category->setName('Main Products'); | ||
|
||
$product = new Product(); | ||
$product->setName('Foo'); | ||
$product->setPrice(19.99); | ||
// relate this product to the category | ||
$product->setCategory($category); | ||
|
||
// save the whole | ||
$product->save(); | ||
|
||
return new Response( | ||
'Created product id: '.$product->getId().' and category id: '.$category->getId() | ||
); | ||
|
@@ -363,15 +363,15 @@ before. First, fetch a ``$product`` object and then access its related | |
|
||
// ... | ||
use Acme\StoreBundle\Model\ProductQuery; | ||
|
||
public function showAction($id) | ||
{ | ||
$product = ProductQuery::create() | ||
->joinWithCategory() | ||
->findPk($id); | ||
|
||
$categoryName = $product->getCategory()->getName(); | ||
|
||
// ... | ||
} | ||
|
||
|
@@ -395,7 +395,7 @@ inserted, updated, deleted, etc). | |
To add a hook, just add a new method to the object class:: | ||
|
||
// src/Acme/StoreBundle/Model/Product.php | ||
|
||
// ... | ||
class Product extends BaseProduct | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ perform a certain action. | |
.. image:: /images/book/security_authentication_authorization.png | ||
:align: center | ||
|
||
Since the best way to learn is to see an example, let's dive right in. | ||
Since the best way to learn is to see an example, we'll dive right in. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, this one is harder :). How about:
|
||
|
||
.. note:: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -336,7 +336,7 @@ for importing service configuration from third-party bundles. | |
Importing Configuration with ``imports`` | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
So far, you've placed our ``my_mailer`` service container definition directly | ||
So far, you've placed your ``my_mailer`` service container definition directly | ||
in the application configuration file (e.g. ``app/config/config.yml``). Of | ||
course, since the ``Mailer`` class itself lives inside the ``AcmeHelloBundle``, | ||
it makes more sense to put the ``my_mailer`` container definition inside the | ||
|
@@ -535,12 +535,12 @@ If you want to expose user friendly configuration in your own bundles, read the | |
Referencing (Injecting) Services | ||
-------------------------------- | ||
|
||
So far, our original ``my_mailer`` service is simple: it takes just one argument | ||
So far, the original ``my_mailer`` service is simple: it takes just one argument | ||
in its constructor, which is easily configurable. As you'll see, the real | ||
power of the container is realized when you need to create a service that | ||
depends on one or more other services in the container. | ||
|
||
Let's start with an example. Suppose you have a new service, ``NewsletterManager``, | ||
Starting with an example, suppose you have a new service, ``NewsletterManager``, | ||
that helps to manage the preparation and delivery of an email message to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
a collection of addresses. Of course the ``my_mailer`` service is already | ||
really good at delivering email messages, so you'll use it inside ``NewsletterManager`` | ||
|
@@ -576,7 +576,7 @@ fairly easily from inside a controller:: | |
|
||
This approach is fine, but what if you decide later that the ``NewsletterManager`` | ||
class needs a second or third constructor argument? What if you decide to | ||
refactor our code and rename the class? In both cases, you'd need to find every | ||
refactor your code and rename the class? In both cases, you'd need to find every | ||
place where the ``NewsletterManager`` is instantiated and modify it. Of course, | ||
the service container gives you a much more appealing option: | ||
|
||
|
@@ -810,9 +810,9 @@ other third-party bundles to perform tasks such as rendering templates (``templa | |
sending emails (``mailer``), or accessing information on the request (``request``). | ||
|
||
You can take this a step further by using these services inside services that | ||
you've created for your application. Let's modify the ``NewsletterManager`` | ||
you've created for your application. Beginning by modifying the ``NewsletterManager`` | ||
to use the real Symfony2 ``mailer`` service (instead of the pretend ``my_mailer``). | ||
Let's also pass the templating engine service to the ``NewsletterManager`` | ||
Also pass the templating engine service to the ``NewsletterManager`` | ||
so that it can generate the email content via a template:: | ||
|
||
namespace Acme\HelloBundle\Newsletter; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, how about: