参数为可为空且未提供任何空值

时间:2018-07-13 12:08:35

标签: symfony knpmenubundle

我正在使用KnpMenuBundle生成菜单的子项。

对于每个类别,我都有一个子类别。我在方法中传递了两个参数(如下所述,在控制器中)。

类别的原则菜单效果很好,但是当我单击其中一个子猫时,出现此错误:

enter image description here

public function souscategorieAction(string $cat,string $subcat,Request $request)
{
    $em = $this->getDoctrine()->getManager();

    $query1 = 'SELECT p.*,(SELECT min(h.prix) FROM Histprix h,Urlproduit u
                WHERE h.urlproduit_id=u.id and u.produit_id=p.id  ) as "prixmin",(SELECT max(h.prix) FROM Histprix h,Urlproduit u
                WHERE h.urlproduit_id=u.id and u.produit_id=p.id  ) as "prixmax", (select count(*) from produit_revendeur  where produit_id=p.id) as "offre"
            FROM  Produit p,Subcat sub,Categorie cat
            WHERE p.status=1 and p.subcat_id=sub.id and sub.categorie_id=cat.id and and cat.nom like'.$cat.' and sub.nom like'.$subcat.';';


    $statement = $em->getConnection()->prepare($query1);
    $statement->execute();
    $produit = $statement->fetchAll();

    $paginator=$this->get('knp_paginator');
    $produits=$pagination= $paginator->paginate (
            $produit,
            $request->query->getInt('page',1),
            $request->query->getInt('limit',5));


    return $this->render('ProductBundle:Product:mobilepage.html.twig', array('produits'=>$produits,'souscategorie'=>$subcat ,'categorie'=>$cat));

这是我的路线:

souscat:
    path:     /{categorie}/{souscategorie}
    defaults: { _controller: ProductBundle:Product:souscategorie } 

这是我的MenuBuilder:

public function createMainMenu(array $options) {
        $c = "";
        $s = "";
        $menu = $this->factory->createItem('root');
        $menu->addChild('Accueil', array('route' => 'home'));

        $categories = $this->em->getRepository('ProductBundle:Categorie')->findAll();
        $subcats = $this->em->getRepository('ProductBundle:Subcat')->findAll();
foreach ($categories as $c) {


            switch ($c) {
                case "Telephonie":
                    $menu->addChild($c, array('route' => 'telephonie'));
                    break;
                case "Informatique":
                    $menu->addChild($c, array('route' => 'informatique'));

                    break;
                case "TV SON Vidéo":
                    $menu->addChild($c, array('route' => 'tvsonvideo'));

                    break;
                case "Electroménager":
                    $menu->addChild($c, array('route' => 'electromenager'));

                    break;
                case "Impression":
                    $menu->addChild($c, array('route' => 'impression'));

                    break;
            }
            foreach ($subcats as $s) {
                if ($c->getNom() == $s->getCategorie()->getNom())

                    $menu[$c->getNom()]->addChild($s->getNom(), ['route' => 'souscat', 'routeParameters' => array('categorie' => $c->getNom(), 'souscategorie' => $s->getNom())]);
            }
        }



    $menu->addChild('Contact', array('route' => 'contactus'));



    return $menu;
}

1 个答案:

答案 0 :(得分:1)

您可以尝试使用与变量相同的名称重命名函数参数吗?

发件人

public function souscategorieAction(string $cat,string $subcat,Request $request)

收件人

public function souscategorieAction(string $categorie,string $souscategorie,Request $request)