http://rockalabs.com
AlejandroPrzCu
Renier Ricardo Figueredo
//Instalar el instalador de symfony en nuestra PC
> sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony
//Crear un nuevo proyecto
> symfony new my_project lts
//Ejecutar la aplicación
> cd my_projet
> php app/console server:run
Ir a http://localhost:8000/
//src/AppBundle/Controller/DefaultController.php
…
class DefaultController extends Controller
{
/**
* @Route("/hello/{name}", name="hello_world")
*/
public function helloAction($name)
{
return new Response(‘Hello ’.$name);
}
}
http://localhost:8000/hello/renier
//Ejecutar
> php app/console doctrine:generate:entity
//Genera
src/AppBundle/Entity/Person.php
src/AppBundle/Repository/PersonRepository
//Crear la bd
> php app/console doctrine:database:create
//Actualizar la bd
> php app/console doctrine:database:update --force
//src/AppBundle/Entity/Person.php
/**@ORM\Table(name="person")*/
class Person
{
/**@ORM\Column(name="firstName", type="string", length=255, unique=true)*/
protected $firstName;
//...
public function __toString()
{
return $this->getFirstName().’ ‘.$this->getLastName();
}
//...
}
//src/AppBundle/Repository/PersonRepository
class PersonRepository extends EntityRepository
{
public getByFirstName($firstName)
{
return $this->createQueryBuilder('person')
->andWhere('person.firstName = :firstName')
->andWhere(‘person.active = 1’)
->setParameter('firstName', $firstName)
->getQuery()
->getOneOrNullResult()
;
}
}
//app/Resources/views/base.html.twig
<html>
<body>
<h1>App hello world</h1>
{% block content %}
{% endblock %}
</body>
</html>
//app/Resources/views/default/hello.html.twig
{% extends 'base.html.twig' %}
{% block content %}
Hello {{ person }}
{% endblock %}
/**@Route("/hello/{name}", name="hello_world") */
public function helloAction($name)
{
$person = $this->getDoctrine()->getRepository('AppBundle:Person')
->getByFirstName($name)
;
if (!$person)
throw $this->createNotFoundException();
return $this→render(‘/default/hello.html.twig’, [‘person’ => $person]);
}
http://localhost:8000/hello/renier
Acceder a http://localhost:8000/admin/person
Comenzar a implementar las funcionalidades necesarias para el CRUD
El comando genera: La clase controladora, PersonModel, Las vitas del CUS, El Formulario, El Filtro y las pruebas automáticas
$client = static::createClient();
$crawler = $client->request('GET', '/hello/renier');
$this->assertGreaterThan(0,
$crawler->filter('html:contains("Hello renier")')->count()
);
$this
->go(‘/hello/renier’)
->see(‘Hello renier’)
;
http://rockalabs.com
AlejandroPrzCu
Renier Ricardo Figueredo