根据查询字符串设置下拉值

时间:2018-05-04 15:13:54

标签: php html codeigniter bootstrap-4 query-string

我正在使用Bootstrap 4和CodeIgniter 3.

我的页面显示一个简单的下拉组,其中包含各种选项。默认值为“请选择”。我想根据URL查询字符串设置下拉列表的值。

我的HTML是;

SeleniumRCTestLibraryGradle
|--src/main/java/com/dummy/jb/ (Own project libraries)
|--src/test/java/com/dummy/jb/ (Own Test Classes and Test Suites)
|  |--Main/Specs/*.java (Own Test Classes)
|  |--TestSuite/ (Own Test Suites)
|     |--Tenant/
|        |--ChannelX
|           |--TenantChannel_PlatformEnv_TestSuiteName.java (Single Test Suite to run)
|--JRE System Library (jre1.8.0_162)
|--Project and External Dependencies (downloaded by build.gradle configuration)
|--bin/
|--gradle/
|  |--wrapper/
|     |--gradle-wrapper.jar
|     |--gradle-wrapper.properties
|--lib/ (Other libraries)
|--src/
|--build.gradle
|--gradle.properties
|--gradlew
|--gradlew.bat
|--settings.gradle

我的查询字符串是;

<div class="input-group">
 <div class="input-group-prepend">
    <a href="#" class="btn dropdown-toggle" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Please Select</a>
    <div class="dropdown-menu">
        <a href="#" class="dropdown-item" value="1">Apple</a>
        <a href="#" class="dropdown-item" value="2">Orange</a>
        <a href="#" class="dropdown-item" value="3">Pear</a>
        <a href="#" class="dropdown-item" value="4">Blue</a>
        <a href="#" class="dropdown-item" value="5">Yellow</a>
    </div>
 </div>
</div>

因此,如果网址中有www.example.com/search/results?coll_id=3 ,我希望在页面加载的下拉列表中选择值coll_id=3

我是否需要在某处设置Pear

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

在您的控制器方法中,在$this->load->view(...);之前添加以下行。

$data['coll_id'] = $this->input->get('coll_id');

您可以使用PHP三元运算符?:并使用bootstrap的active类来设置所选项目。

查看代码:

<div class="input-group">
 <div class="input-group-prepend">
    <a href="#" class="btn dropdown-toggle" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Please Select</a>
    <div class="dropdown-menu">
        <a href="#" class="dropdown-item <?php echo ($coll_id == "1" ? 'active' : '');?>" value="1">Apple</a>
        <a href="#" class="dropdown-item <?php echo ($coll_id == "2" ? 'active' : '');?>" value="2">Orange</a>
        <a href="#" class="dropdown-item <?php echo ($coll_id == "3" ? 'active' : '');?>" value="3">Pear</a>
        <a href="#" class="dropdown-item <?php echo ($coll_id == "4" ? 'active' : '');?>" value="4">Blue</a>
        <a href="#" class="dropdown-item <?php echo ($coll_id == "5" ? 'active' : '');?>" value="5">Yellow</a>
    </div>
 </div>
</div>