How do I read configuration settings from Symfony2 config.yml?

I have added a setting to my config.yml file as such: app.config: contact_email: [email protected] … For the life of me, I can’t figure out how to read it into a variable. I tried something like this in one of my controllers: $recipient = $this->container->getParameter(‘contact_email’); But I get an error saying: The parameter “contact_email” must be … Read more

Should everything really be a bundle in Symfony 2.x?

I’m aware of questions like this, where people tend to discuss the general Symfony 2 concept of bundle. The thing is, in a specific application, like, for instance, a twitter-like application, should everything really be inside a generic bundle, like the official docs say? The reason I’m asking this is because when we develop applications, … Read more

Count Rows in Doctrine QueryBuilder

I’m using Doctrine’s QueryBuilder to build a query, and I want to get the total count of results from the query. $repository = $em->getRepository(‘FooBundle:Foo’); $qb = $repository->createQueryBuilder(‘n’) ->where(‘n.bar = :bar’) ->setParameter(‘bar’, $bar); $query = $qb->getQuery(); //this doesn’t work $totalrows = $query->getResult()->count(); I just want to run a count on this query to get the total … Read more

What is the difference between .yaml and .yml extension? [duplicate]

This question already has answers here: Is it .yaml or .yml? (4 answers) Closed 3 years ago. I read them on YAML-wikipedia but not really understood the main difference between them. I saw there are someone using .yaml extension, however, Symfony2 use .yml extension. YAML is a human-readable data serialization format that takes concepts from … Read more

How to render a DateTime object in a Twig template

One of my fields in one of my entities is a “datetime” variable. How can I convert this field into a string to render in a browser? Here is a code snippet: {% for game in games %} … <td> {{game.gameTeamIdOne.teamName}} </td> <td> {{game.gameTeamIdTwo.teamName}} </td> <td> {{game.gameDate}}</td> </tr> {% endfor %} Here is the variable … Read more

Running Composer returns: “Could not open input file: composer.phar”

I am new to symfony2 and reading symblog. In third chapter while trying with data-fixtures I tried the command: php composer.phar update but I got the error: Could not open input file: composer.phar So I googled a little and tried php composer.phar install but still getting the same error. So please guide how to deal … Read more

On delete cascade with doctrine2

I’m trying to make a simple example in order to learn how to delete a row from a parent table and automatically delete the matching rows in the child table using Doctrine2. Here are the two entities I’m using: Child.php: <?php namespace Acme\CascadeBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name=”child”) */ class Child … Read more