0
votes

I'm learning Symfony; got a simple page working in routing.yml, on my site at http://mynews.localhost:

MyNewsHere:
pattern:  /mynews
defaults: { _controller: MyNewsBundle:NewsStory:index }

This is the controller:

<?php

namespace MyNewsHere\MyNewsBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class MyNewsHereController extends Controller
{
    public function indexAction()
    {
        /*
         * The action's view can be rendered using render() method
         * or @Template annotation as demonstrated in DemoController.
         *
         */
        return $this->render('MyNewsBundle:MyNews:index.html.twig');
    }
}

and this is the index.html.twig:

    <link rel="stylesheet" type="text/css" href="{{ asset('bundles/MyNews/index.css') }}" media="all">

Hello World!

<h2>TEST</h2>

However, I wanted to expand beyond the Hello World example and actually get a PDO MySQL query to run, as seen at this site. I can do the PHP/PDO/MySQL example for a simple Twig-based PHP site, without Symfony; but how can I get this to run for my Symfony site within the bundles like the MyNews example above? I did look up 'pdo mysql symfony' on Google, but am not quite sure how to do this at beginner level with Symfony... did look on the Symfony manual but am a bit confused.

Any advice would be appreciated; I'm a beginner at using Twig, thought using Symfony would expand it.

N.B. The link given is for a site only on my localhost.

1

1 Answers

2
votes

First of all, Twig is just a templating engine. It can only do some less logic programming things, not the heavy part, that should be done in PHP with a framework like Symfony2.

Secondly, take a look at the documentation, especially "The Book". Read the first, second, third ... article. Once you get at the "Databases & Doctrine" article, you will understand what Symfony does and what twig does. That article explains how you use a database in your Symfony project.