How can I connect a view and a controller [closed]

1

Context

I'm learning ?

    
asked by Sermanes 15.03.2016 в 09:29
source

1 answer

5

So that you understand the idea of the MVC

It's the basic idea. Now from Symfony's point of view, it would work in the following way:

namespace Nombre\NamespaceBundleArtekBoard\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

//List es el nombre del controlador, acá uso una función userList (el Action es para identificar por symfony2 que usas una 'acción')
class ListController extends Controller
{
    public function userListAction()
    {
        return $this->render('NombreDelBundle:RutaDeLaCarpetaView:list.html.twig');
    }    
}

And in the view (list.html.twig, for this example)

<html>
   <head></head>
   <body>
      Hola Mundo ^^
   </body>
</html>

But, how do I get from the URL (for example www.dominio.cl/listarUsuario) to the controller and all that ?, I create a route in the config / routing of my Bundle

alias_de_yaml:
    path:     /user/
    defaults: { _controller: NombreDelBundle:List:userList }

(Note that the 'Controller' of UserController and the Action of userListAction are not added)

That would be a very basic example of the idea you need.

An interesting link is this (it's a bit old, since we're going in version 2.8.2 and 3.0.1) where you can learn the basics of Symfony2

link

Also if you want you can see this 'project' (which I have shot) using Symfony 2.8 for you to make a reference.

link

greetings

    
answered by 17.03.2016 / 14:30
source