Reynier
Reynier

Reputation: 2478

Redirect to the selected tab

I'm using Twitter Bootstrap in Symfony 1 application. I've a tabbed navigation but I want to get redirected to the same tab I was after perform a add action. See this image as you may see I in Emisores tab, I want after perform a Add action (is "Crear Nuevo") I got redirected to the same tab. For redirection I use this:

$this->redirect('admin/index');

Is that possible? How?

Upvotes: 0

Views: 1574

Answers (1)

antony
antony

Reputation: 2893

In your controller

// \apps\myApp\modules\profile\actions\actions.class.php
public function executeUpdate()
{
    // Handle form submit and update

    $this->getUser()->setFlash('activeTab', 'profile');
    $this->redirect('admin/index');
}

Now in your template, you can tell what was the last activated tab because you stored the name of it in the flash object before you did the redirect. So retrieve the flash value to determine which tab to activate in your template like this:

// \apps\myApp\modules\admin\templates\indexSuccess.php
<script>
     <?php 
     // Would be better if assigned this in your controller and passed it to the template
     $activeTab = $sf_user->getFlash('activeTab', 'default_tab_id');
     ?>
     $('#myTab a[href="#<?php echo $activeTab ?>"]').tab('show');
</script>

Upvotes: 2

Related Questions