Barrosy
Barrosy

Reputation: 1457

Symfony and data handling

Lately I have gotten myself into PHP framework Symfony and I got to understand some fundementals, however I am having trouble with finding a good example concerning data retrieval (from a database) in Symfony.

Since Symfony is an object oriented way of programming, I thought it would be best to retreive data, save certain fields as properties of a certain object (name would be related to the name of the table) and return it to a twig template.

My template would look something like this:

{% extends 'base.html.twig' %}

{% block body %}
    <h1>Page: {{ page.title }}</h1>
    {% for x in Object_Name %}
        { x.age}
    {% endfor %}
{% endblock %}

How should I define a class or object and its properties and how should a controller look like to pass such object to the template given in the example above? I have been looking around on the web but it seems like there is not much content concerning data handling and Symfony PHP.

Can anyone refer me to a page I can look for this kind of information?

Because I have been used to working with MVC in ASP.NET, I know these things would happen in a folder called models which would contain classes and its properties, but this does not seem the case with Symfony.

Upvotes: 0

Views: 51

Answers (1)

KhorneHoly
KhorneHoly

Reputation: 4766

You're looking for Entities in Symfony2.

Those are classes, that represent tables in your database.

You can create them from existing database tables or create new one over generated entities.

Have a closer look into the documentation http://symfony.com/doc/current/book/doctrine.html

Upvotes: 2

Related Questions