Symfony2 – Security

Symfony’s security system is incredibly powerful, but it can also be confusing to set up. In this chapter, you’ll learn how to set up your application’s security step-by-step, from configuring your firewall and how you load users to denying access and fetching the User object. Depending on what you need, sometimes the initial setup can be tough. But once it’s done, Symfony’s security system is both flexible and (hopefully) fun to work with.

Source: http://symfony.com/doc/current/book/security.html

I have followed all those steps until step “D) Configuration Done!”. It was easy to work with. The big challenge I have faced was to create a login form. Apparently it is more difficult because, at the time, my application was not well developed. After I get better at application development, I will give a try to develop a login form loading users from database. It is also important to learn how to deny access, roles and other Authorization but is not urgent! I have not given a try to logging out but I will when I am available.

About web debug toolbar, if you don’t have a </body> tag in page the toolbar will not appear!

Doctrine2 – Decimal Type

I have a column in my table with decimal(8,6). What is the right way to define this field?

There are two parameters: precision and scale. The precision is the number of digits in the number. The scale is the maximum number of decimal places. The annotation for that column would be:

@ORM\Column(type="decimal", precision=8, scale=6)

Twig – Date

If the value passed to the date filter is null, it will return the current date by default. If an empty string is desired instead of the current date, use a ternary operator.

{{ entity.dob is empty ? "" : entity.dob | date ("Y-m-d") }}

Steps to start working on symfony2

After I have installed and configured Symfony2, the next steps I took are:

    php app/console

  1. generate:bundle (any name for bundle)
  2. doctrine:database:create (to create a database on database server)
  3. doctrine:generate:entity (after I have written names and framework has created entity, it was necessary to mapping objects
  4. doctrine:generate:entities nameBundle (to generate setters and getters methods)
  5. doctrine:schema:update --dump-sql (to confirm SQL queries)
  6. doctrine:schema:update --force (if O/R Mapping is well done)
  7. doctrine:generate:crud (to create CRUD operations for each entity)

When I was mapping O/R, I always typed php app/console doctrine:schema:validate to check out mapping. Another useful command is php app/console list.