Use URL in Yii to control the Bootstrap Activity tab

Source: Internet
Author: User
As the chief developer of MutableLabs, I found that when using the YiiBootstrap tab (Tabs) component, we sometimes need users to directly view the specified tab instead of the first one. YiiBootstrap has provided the & quot; active & quot; variable, which allows you to define which tab to display in PHP. I found that this method is also

As the chief developer of Mutable Labs, I found that when using the Yii Bootstrap tab (Tabs) component, we sometimes need users to directly view the specified tab instead of the first one. Yii Bootstrap has provided the "active" variable, through which you can define which tab to display in PHP. I found that this method is also very troublesome, because we need to insert PHP code or extend the tab component for each tab component to implement it in some way.

In any case, I found the best method for me-the JQuery solution, as shown below. Make sure that the ID of the tab area is "tabs". if there are multiple tab areas, use the same code for the tabs in other areas. You only need to put this code in the layout or header file...

 《script》    $(document).ready(function() {        $('#tabs a:contains("
 ")').tab('show');    });《script》
 

Then you only need to set the "tab" variable in the URL. The configured tab is displayed when the page is loaded. The following is an example of how to use it, provided that you have added the above code...

 widget("bootstrap.widgets.TbTabs", array(    "id" => "tabs",    "type" => "tabs",    "tabs" => array(        array("label" => "Books", "content" => "Some content", "active" => true),        array("label" => "Authors", "content" => "Some content"),    ),)); ?>

The access URL is as follows...

Index. php? R = controller/action & tab = Authors

The "Authors" tab is used as the activity tab instead of "Books". if no tab is specified in the GET parameter, the default activity tab is used, as shown in the "Books" tab in the example.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.