How can you use $_GET to control tab navigation in a PHP application with Bootstrap?
To control tab navigation in a PHP application with Bootstrap using $_GET, you can pass a parameter in the URL and use it to determine which tab should be active. By checking the value of the parameter in $_GET, you can dynamically set the active class on the corresponding tab.
<?php
$activeTab = isset($_GET['tab']) ? $_GET['tab'] : 'tab1'; // Default to tab1 if no tab parameter is provided
function isActiveTab($tab) {
global $activeTab;
return $activeTab == $tab ? 'active' : '';
}
?>
<!-- Bootstrap tab navigation -->
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link <?php echo isActiveTab('tab1'); ?>" href="?tab=tab1">Tab 1</a>
</li>
<li class="nav-item">
<a class="nav-link <?php echo isActiveTab('tab2'); ?>" href="?tab=tab2">Tab 2</a>
</li>
<li class="nav-item">
<a class="nav-link <?php echo isActiveTab('tab3'); ?>" href="?tab=tab3">Tab 3</a>
</li>
</ul>
Keywords
Related Questions
- What are the implications of defining an interface that restricts the types of parameters accepted by different classes in PHP?
- In what scenarios would it be necessary to create a specific user account with specific group memberships for executing Powershell scripts via PHP on a Windows server?
- What is the purpose of using the rand() function in PHP?