0

I dont have a controller action for homepage because Sonata Page is mandatary. But when user is already authenticated and return to the root / (basically the homepage), I want that new homepage for a authenticated user became his dashboard (address /profile/) That's why I figured out a redirection from homepage (/) to dashboard (/profile/).

Where/How can I put this redirection? (and avoid a javascript redirection)

Thanks for any help

up2europe
  • 41
  • 5
  • I found a related question that can help http://stackoverflow.com/questions/32046565/customer-home-page-sonata-page – up2europe Sep 23 '15 at 09:24

2 Answers2

0

You don't need to set a redirection, just in your configuration file add your default target path :

firewalls:
  secured_area:
    form_login:
        always_use_default_target_path: true
        default_target_path: /loggedinpage
Anas EL KORCHI
  • 2,008
  • 18
  • 25
  • Not work! This work for user just logged in (redirected to /profile/ in my case). But if user again come to the homepage / there is not a redirection on his dashboard (/profile/). That's what I'm trying to do. Thank you anyway – up2europe Sep 23 '15 at 07:13
0

Ok I got it You just create your action :

/**
 * Home page
 *
 * @Route("/", name="homepage")
 */
public function homeAction()
{
    /** @var User $user */
    $user = $this->get('security.token_storage')->getToken()->getUser();
    if (is_object($user) and $user instanceof User) {
        return $this->redirectToRoute('sonata_user_profile_show');
    }

    return $this->render('YourBestBundle:Template:template_home_layout.html.twig');
}

then on database "page__page" table you search for homepage route with parent_id=null and in column "route_name" where was "page_slug" selected (means handled by sonata page) you replace with your new Homepage route "homepage" (from homeAction() ) . That's it

up2europe
  • 41
  • 5