参数可为空且未提供空值

Argument is nullable and no null value has been provided

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

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

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

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;
}

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

来自

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

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