Difference between #6 and #7 of
Handling Bootstrap active tabs in Yii via URL

Changes

Title unchanged

Handling Bootstrap active tabs in Yii via URL

Category unchanged

How-tos

Yii version unchanged

Tags unchanged

bootstrap, tabs, jquery

Content changed

I ([www.jamesbarnsley.com](http://www.jamesbarnsley.com "www.jamesbarnsley.com")) found that when using the Yii Bootstrap tabs component you will sometimes want to direct the user to a specific tab and not necessarily the first tab. Yii Bootstrap already provides the "active" variable so you can define whether the tab is the active tab or not in PHP. I generally find though that a PHP solution to this problem is rather cumbersome as every tab component will need the PHP code inserted or you will have to extend the tab component somehow to do it.

Anyways I found that a JQuery solution worked the best for me and here it is. Please make sure you have given your tabbed area an id of "tabs", if you have multiple tabbed areas then using this code again for the other tabbed area is an option. Just place this code into your "layout" or "header" file ...
[...]
index.php?r=controller/action&tab=Authors

The tabs will now use the "Authors" tab as the active tab and not the "Books" tab on page load. If no GET param for the tab is specified then it will use the default active tab which in this example is the "Books" tab.

 
 
[www.jamesbarnsley.com](http://www.jamesbarnsley.com "www.jamesbarnsley.com")
3 0
7 followers
Viewed: 40 537 times
Version: 1.1
Category: How-tos
Written by: JamesBarnsley
Last updated by: JamesBarnsley
Created on: Jan 19, 2013
Last updated: 8 years ago
Update Article

Revisions

View all history