Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Problem of Curly Brackets in my controller Php Symfony

I want to call my function but when I call it I have a problem with curly Brackets at the end of my code and i have this error Error SYMFONY ( {} ) in my Controller.

I have no idea where to put them for my code to work. I have this problem when I add my function that allows me to retrieve the
history of the action. The mentioned function goes as this:

$this->logHistory->addHistoryConnection($project->getId(), $user->getId(), 'Delete Local Suf', $sf_code);

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Function Supp Suf

/**
 * @Route("/creation/suf/supp", name="suf_supp")
 */
public function suf(
    Request $request,
    ShapesRepository $shapesRepository
) {
    $params = $this->requestStack->getSession();
    $projet = $params->get('projet');

    $modules = $params->get('modules');
    $fonctionnalites = $params->get('fonctionnalites');

    $user = $this->getUser()->getUserEntity();
    $manager = $this->graceManager;
    $mapManager = $this->mapManager;

    $countElements = $mapManager->getCount();
    $shapes = $shapesRepository->findBy(array('projet' => $projet->getId()));

    $adresseWeb = $this->getParameter('adresse_web');
    $carto = $params->get('paramCarto');
    $centrage = $params->get('centrage');
    $cableColor = $params->get('cableColor');

    $sf_code = '';
    if ($request->get('suf') != '') {
        $sf_code = $request->get('suf');
    }

    $suf = $manager->getSuf($sf_code);

    $success = '';
    $error = '';
    $warning = '';

    if ($request->query->get('success')) {
        $success = $request->query->get('success');
    } elseif ($request->query->get('error')) {
        $error = $request->query->get('error');
    } elseif ($request->query->get('warning')) {
        $warning = $request->query->get('warning');
    }

    if ($request->isMethod('POST')) {
        if ($request->request->get('sf_code') != '') {
            $sf_code = $request->request->get('sf_code');
        }

        if ($request->get('val') != '') {
            $val = $request->get('val');
        }

        $dir = $this->getparameter('client_directory');
        $dossier = str_replace(' ', '_', $projet->getProjet());
        $dir = $dir . $dossier . '/documents/';

        $cable = $val[0];
        $chem = $val[1];

        $t_suf = $this->graceCreator->supprimeSuf($sf_code, $cable, $chem);

        if ($t_suf[0][0] == '00000') {
            $this->logHistorique->addHistoryConnection($projet->getId(), $user->getId(), 'Suppression Suf Local', $sf_code);


            // $creator->delDirObjet( $st_code, $dir );
            $data = new JsonResponse(array("success" => "create!"));
            return $data;
        } else {
            $data = new JsonResponse(array("error" => "Error : " . $t_suf));
            return $data;
        }
        return $this->render('Modifications/supSuf.html.twig', array(
        'user' => $user,
        'paramCarto' => $carto,
        'cableColor' => $cableColor,
        'suf' => $suf,
        'adresseWeb' => $adresseWeb,
        'centrage' => $centrage,
        'shapes' => $shapes,
        'projet' => $projet,
        'modules' => $modules,
        'fonctionnalites' => $fonctionnalites,
        'countElements' => $countElements
    ));
    }
}

>Solution :

Your only return statement is inside of an if condition. If the code does not pass the condition, it has nothing to return. The code must return something in all possible cases. If you are not still used to these practices, an IDE might guide you until it becomes a routine. PHPStorm is my personal preference.


BTW, I recommend you to switch from the array() syntax to the more globally accepted [] although you must be in PHP 5.4 or higher.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading