Entity Clientes:
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Clientes
*
* @ORM\Table(name="clientes", uniqueConstraints={@ORM\UniqueConstraint(name="numcliente", columns={"numcliente"})}, indexes={@ORM\Index(name="apellidos", columns={"apellidos"}), @ORM\Index(name="codigotargeta", columns={"codigotargeta"}), @ORM\Index(name="apellidos_2", columns={"apellidos"}), @ORM\Index(name="email", columns={"email"})})
* @ORM\Entity
*/
class Clientes
{
/**
* @var integer
*
* @ORM\Column(name="numcliente", type="integer", nullable=false)
*/
private $numcliente;
/**
* @var string
*
* @ORM\Column(name="nombre", type="string", length=60, nullable=false)
*/
private $nombre;
/**
* @var string
*
* @ORM\Column(name="apellidos", type="string", length=200, nullable=false)
*/
private $apellidos;
/**
* @var string
*
* @ORM\Column(name="movil", type="string", length=20, nullable=false)
*/
private $movil;
/**
* @var string
*
* @ORM\Column(name="foto", type="blob", length=16777215, nullable=false)
*/
private $foto;
/**
* Set numcliente
*
* @param integer $numcliente
*
* @return Clientes
*/
public function setNumcliente($numcliente)
{
$this->numcliente = $numcliente;
return $this;
}
/**
* Get numcliente
*
* @return integer
*/
public function getNumcliente()
{
return $this->numcliente;
}
/**
* Set nombre
*
* @param string $nombre
*
* @return Clientes
*/
public function setNombre($nombre)
{
$this->nombre = $nombre;
return $this;
}
/**
* Get nombre
*
* @return string
*/
public function getNombre()
{
return $this->nombre;
}
/**
* Set apellidos
*
* @param string $apellidos
*
* @return Clientes
*/
public function setApellidos($apellidos)
{
$this->apellidos = $apellidos;
return $this;
}
/**
* Get apellidos
*
* @return string
*/
public function getApellidos()
{
return $this->apellidos;
}
/**
* Set movil
*
* @param string $movil
*
* @return Clientes
*/
public function setMovil($movil)
{
$this->movil = $movil;
return $this;
}
/**
* Get movil
*
* @return string
*/
public function getMovil()
{
return $this->movil;
}
/**
* Set foto
*
* @param string $foto
*
* @return Clientes
*/
public function setFoto($foto)
{
$this->foto = $foto;
return $this;
}
/**
* Get foto
*
* @return string
*/
public function getFoto()
{
return $this->foto;
}
}
ClientesController.php
class ClientesController extends Controller
{
public function nuevoClienteAction(Request $request)
{
$cliente = new Clientes();
$form = $this->createForm(\AppBundle\Form\ClientesType::class,$cliente);
$form->handleRequest($request);
if ($form->isSubmitted()&& $form->isValid()) {
//Recoge los datos
$cliente = $form->getData();
// you can fetch the EntityManager via $this->getDoctrine()
// or you can add an argument to your action: createAction(EntityManagerInterface $em)
$em = $this->getDoctrine()->getManager();
// tells Doctrine you want to (eventually) save the Product (no queries yet)
$em->persist($cliente);
// actually executes the queries (i.e. the INSERT query)
$em->flush();
return $this->redirect($this->generateUrl(
'clientes'));
}
return $this->render('clientes/nuevoclienteprueba.html.twig',array('formulario'=>$form->createView()));
}
}
ClientesType.php
class ClientesType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{ //setMethod('PATCH')->
$builder->
add('numcliente', IntegerType::class)->
add('nombre', TextType::class,array('label' => 'Nombre','attr' => array('class' => 'form-control','placeholder' => 'Nombre')))->
add('apellidos', TextType::class,array('label' => 'Apellidos','attr' => array('class' => 'form-control','placeholder' => 'Apellidos')))->
add('movil', TextType::class,array('label' => 'Móvil','attr' => array('class' => 'form-control','placeholder' => 'Teléfono Móvil')))->
add('foto', FileType::class,array('label' => 'Foto','required' => '','attr' => array('class' => 'form-control')))->
add('guardar',SubmitType::class, array('label' => 'Guardar','attr' => array('class' => 'btn green')))->getForm();
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\Clientes'
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'appbundle_clientes';
}
}