Yani atılan kılmasıdır, ben: {% render "EcsCrmBundle:Module:checkClock" %}
Symfony2 dal, istisna benim taban şablonunda
Ben ModuleController.php yarattı ...
<?php
namespace Ecs\CrmBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Ecs\CrmBundle\Entity\TimeClock;
class ModuleController extends Controller
{
public function checkClockAction() {
$em = $this->getDoctrine()->getEntityManager();
$user = $this->get('security.context')->getToken()->getUser();
$today = time();
$start = date('Y-m-d 00:00:00');
$entities = $em->getRepository('EcsCrmBundle:TimeClock');
$query = $entities->createQueryBuilder('tc')
->select('tc.in1, tc.out1, tc.in2, tc.out2, tc.in3, tc.out3')
->where('tc.noteBy = :user')
->andWhere('tc.daydate >= :start')
->setParameter('user', $user->getid())
->setParameter('start', $start)
->setMaxResults('1')
->getQuery();
$entities = $query->getSingleResult();
if (empty($entities)) {
$ents = "clocked_out";
$this->get('session')->set('clockedin', 'clocked_out');
} else {
for ($i=1; $i <= 3; $i++) {
if ($entities["in$i"] != NULL) {
$ents = "clocked_in";
if ($i == 1) {
$this->get('session')->set('nextclock', "out$i");
} else {
$x = $i+1;
$this->get('session')->set('nextClock', "out$x");
}
if ($entities["out$i"] != NULL) {
$ents = "clocked_out";
$x = $i+1;
$this->get('session')->set('nextclock', "in$x");
}
if ($entities["out3"] != NULL) {
$ents = "day_done";
}
}
}
}
return $this->render('EcsCrmBundle:Module:topclock.html.twig', array(
'cstat' => $ents,
));
}
}
şey de varsa sorun vardır Ben veritabanından hayır 'sonucu' olduğunu gerçeği ile ilgili bir şey var biliyorum
An exception has been thrown during the rendering of a template ("No result was found for query although at least one row was expected.") in ::base.html.twig at line 161.
500 Internal Server Error - Twig_Error_Runtime
1 linked Exception: NoResultException »
... ama bu değil: belirli bir kullanıcı henüz için belirli bir gün için veritabanı .. i almaya devam ne Ben if (empty($entities)) {
yaparak başardım ??
$entities = $query->getSingleResult();
Doktrin'e bakarsanız \ ORM \ AbstractQuery bunu göreceksiniz
$entity = $query->getOneOrNullResult();
olarak: Ben Değiştir hayır bunu düzeltmek için ipucu ... takdir herhangi bir yardım ...
Nice! Böyle bir konuyla uğraşıyordum ve sen benim için çözdün .. OP için +1 ve Cerad için +1! – Justin
mükemmel çalıştı .. Cevabın seçiminde gecikme için üzgünüm .. – Johnny