简体   繁体   中英

Return value of carsAction() must be of the type array, object returned

My code inside carsAction() function:

return $this->renderView(
     'WebsiteBundle:SearchCars:cars.html.twig',
    [ 'cars' => $cars ]
);

And I get the error:

Return value of carsAction() must be of the type array, string returned

I tried to change renderView to render

return $this->render(
    'WebsiteBundle:SearchCars:cars.html.twig',
            [ 'cars' => $cars ]        
);

but get this error:

Return value of carsAction() must be of the type array, object returned

Solution:

Instead of the array I change the method definition like this

 * @return Response
 */


public function carsAction(Request $request): Response

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM