Sunteți pe pagina 1din 2

:: vs →

Simply put, :: is for class-level properties, and -> is for object-level properties.

If the property belongs to the class, use ::

If the property belongs to an instance of the class, use ->


class Tester
{
public $foo;
const BLAH;

public static function bar(){}


}

$t = new Tester;
$t->foo;
Tester::bar();
Tester::BLAH;

Symfony
Dump
VarDumper component also includes the {% dump %} tag and the {{ dump() }} function for
inspecting variables directly from the Twig templates. The {% dump %} tag dumps variables to
the web debug toolbar (e.g {% dump variable1, variable2 %}), which is the best
alternative when the output of the original template shall not be modified.
On the contrary, the {{ dump() }} function dumps variables inline, so their contents are
displayed alongside the regular template contents (e.g {{ dump(variable1,
variable2) }}).

Último elemtento en oneToMany


//this - oneToMany - collaborateur
$this->getRepository()->findOneBy(
array('collaborateur'=>$collaborateur),
array('id' => 'DESC')
);

$beneficiarioReservas = $em-
>getRepository('CNRTReservasBundle:BeneficiarioReserva')
->findBy(array(
'beneficiarioBoleteria' => $beneficiario->beneficiarioBoleteria,
'anulada' => false,
'fechaServicio' => $fechaSalida));
Equivalencia del Between
SELECT *
FROM contacts
WHERE contact_id BETWEEN 100 AND 200;

This MySQL BETWEEN example would return all rows from the contacts table where the
contact_id is between 100 and 200 (inclusive). It is equivalent to the following SELECT statement:
SELECT *
FROM contacts
WHERE contact_id >= 100
AND contact_id <= 200;

Filtramos objetos de un array según criterios


private function obtenerServicioTramo($idEmpresa, $idLocalidadOrigen,
$idLocalidadDestino, \DateTime $salida)
{
$servicioTramo = null;
$em = $this->getDoctrine()->getManager();
$results = $em→getRepository('CNRTReservasBundle:ServicioARealizar')-
>obtenerServiciosTramos([$idEmpresa], $idLocalidadOrigen,
$idLocalidadDestino, $salida, $salida);

//Filtramos los Servicios Tramo que correspondan a la hora de salida


$results = array_filter($results, function ($obj) use ($salida){
if($obj && $obj instanceof ServicioTramo){
if($obj->horaSalida->format('H:i') == $salida->format('H:i')){
return true;
}
}
return false;
});
// reindexamos array
$results = array_values($results);

//Asumimios que el servicio a realizar buscado es el primero encontrado,


// ya que no debería existir otro
if(sizeof($results) > 0){
$servicioTramo = $results[0];
}

return $servicioTramo;
}

Consola
php bin/console debug:router

| grep "/batata"

S-ar putea să vă placă și