symfony 2 verify type of data stored in a single column
Posted
by
GRafoKI
on Stack Overflow
See other posts from Stack Overflow
or by GRafoKI
Published on 2012-11-01T10:58:36Z
Indexed on
2012/11/01
11:00 UTC
Read the original article
Hit count: 270
In my DB I have a column 'own_product' that contains 2 values ( quantity and name)
In my Edit form I want to check if the first field (quantity) is string and positive or not.
I added a new column 'type-prod' (int , string)
this is my controller :
$request = $this->container->get('request');
if ($request->getMethod() == 'POST')
{
$formel = $request->query->get('edit_formal');
$type_value = $formel['own_product'];
//case int
$type_int= $this ->getDoctrine()
->getEntityManager()
->getRepository('DHG\WelcomeBundle\Entity\type-prod')
->findOneBy(array('type' => 'int'));
//case string
$type_string = $this ->getDoctrine()
->getEntityManager()
->getRepository('DHG\WelcomeBundle\Entity\type-prod')
->findOneBy(array('type' => 'string'));
if (isset($type_value) && $type_int && $type_value > 0 && is_int($type_value))
{
echo 'Success';
}
else echo 'error' ;
}
Thank you !
© Stack Overflow or respective owner