Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3924

Attempted to call an undefined method named "redirect" error in Symfony 4

$
0
0

i have this error in my code and I have writing the "use" but i have this error:

Attempted to call an undefined method named "redirect" of class "App\Controller\SetlocaleController".

My code:

<?php 

namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\RedirectResponse;

class SetlocaleController extends HomeController {

    public function __construct(\Twig\Environment $twig)
    {
        $this->twig = $twig;
    }

    public function setLocaleAction(Request $request, $language = null)
    {
        if($language != null)
        {
            $session->set('_locale', $language);
        }

        $url = $request->headers->get('referer');
        if(empty($url))
        {
            return new response($this->twig->render('page/home.html.twig'));
        }
        else{
            return $this->redirect($url);
        }
    }
}

You have an answer for me please ?


Viewing all articles
Browse latest Browse all 3924

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>