Symfony2我的控制器:要求你为" $ idn"

时间:2017-05-06 20:02:53

标签: php symfony doctrine-orm query-builder

我是一个在点击按钮后设置列名的功能

public function luAction($idn)
{
    $em = $this->getDoctrine()->getManager();
    $rech = $em->getRepository('NewsBundle:News_PNC')->findOneBy($idn);
    if (!$rech) {
        return new Response('Error');
    }
    else {
        $rech->setLu('lu');
        $em->persist($rech);
        $em->flush();
        return $this->redirectToRoute('pnc');
    }
}

你也可以看到我的routing.yml

     lu_news:
         path:  /lu/{idn}
         defaults: {_controller: NewsBundle:news:lu} 

从数据库返回id的函数:

public function pncAction()
{       
    $user= $this->getUser();

    $repository = $this->getDoctrine()->getRepository('NewsBundle:News_PNC');
    $query = $repository->createQueryBuilder('p')
                        ->where('p.pncs = :user')
                        ->addSelect('p.lu')
                        ->addSelect('p.idn')
                       ->andWhere('p.lu = :no')
                        ->leftJoin('p.news','news')
                        ->addSelect('news.id')
                        ->setParameter('user',$user->getId())
                       ->setParameter('no','no')
                        ->getQuery();

    $users = $query->getResult();
    $tab = array();

    $tab1 = array();
    foreach ($users as $user) {
        array_push($tab, $user); //retourne l id du news
        array_push ($tab1,$user['id']); // retourne l id du l'utilisateur connecté
    }

   /* dump($tab);
    exit() ; */

   $repository = $this->getDoctrine()->getRepository('NewsBundle:news');
    $query = $repository->createQueryBuilder('p')
                        ->where('p.id = :id')
                        ->setParameter('id',$tab1[0])
                        ->getQuery();

    $news = $query->getResult();
       return $this->render('popup.html.twig',
        array('user' => $users , 'news'=>$news));
}
}

My Twig:

<a href="{{path('lu_news',{'idn':l.idn})}}" class="btn btn-primary pull-left">Continuer</a>

当我点击按钮时,我在我的网址中看到了这一点,这意味着它为我带来了正确的ID:

    http://127.0.0.1/sym/web/app_dev.php/lu/2

在获取此网址后,它会显示此错误

控制器&#34; NewsBundle \ Controller \ newsController :: luAction()&#34;要求您为&#34; $ idn&#34;提供价值。参数(因为没有默认值或因为在此之后存在非可选参数)。

0 个答案:

没有答案