Compruebe si ArrayCollection está vacío
Tengo una Orden de Entidad que mantiene Proveedores en una Arraycollection. En mi controlador quiero comprobar si esta arraycollection está vacía:
$suppliers = $order->getSuppliers();
Lo intenté:
if(!($suppliers)) {}
if(empty($suppliers)) {}
¿Alguna idea?
25
2 answers
Doctrina ArrayCollection tiene un método isEmpty
que hará lo que usted está buscando.
if ($suppliers->isEmpty()) { }
Echa un vistazo a la documentación para ello aquí
65
Author: Ken Hannel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-07-29 18:14:59
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-07-29 18:14:59
También puedes usar la función PHP count()
:
if (count($suppliers) < 1) { }
5
Author: A.L,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-12-17 14:34:03
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-12-17 14:34:03