Problem with Jsonresponse in my Symphony4 Controller

Asked

Viewed 26 times

0

I have a problem with my Jsonreponse in my template.

V Controler V

<?php
// src/Controller/DefaultController.php
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;

class DefaultController extends AbstractController
{

    public function index(Request $request)
    {
        $array[] = [
            "text" => "Band"];
        $array[] = [
            "text" => "Tour",];
        $array[] = [
            "text" => "Contact",];
        $array[] = [
            "text" => "Merchandaise",];

    $form = $this->createFormBuilder()
            ->add('name', TextType::class,array(
        'attr'=> ['class' => 'w3-input w3-border']))
            ->add('email', EmailType::class,array(
        'attr'=> ['class' => 'w3-input w3-border']))
            ->add('message', TextareaType::class,array(
        'attr'=> ['class' => 'w3-input w3-border']))
            ->add('send', SubmitType::class,array(
        'attr'=> ['class' => 'w3-input w3-border w3-button w3-black w3-section w3-right']))
            ->getForm();

                return $this->render('body.html.twig' , [
                'arrays' => $array,
                'form' => $form->createView(), 
            ]);
   }
    public function indexN2()
        {       
        return new JsonResponse(array('code'=>$code,'msg'=>$msg)
        $request->'request'->$query("name"),
        $request->'request'->$query("email"),
        $request->'request'->$query("message")
        );
        }


}
```````````````

Execption
https://imgur.com/a/XVkvU4M


1 answer

0


You missed a comma on that line

return new JsonResponse(array('code'=>$code,'msg'=>$msg),
  • Thanks :) solved the problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.