Codeigniter从网址获取参数?

时间:2017-08-31 12:16:25

标签: codeigniter url get

我有一个观点

<div class="panel-body">
            <div class="table-responsive">
                <table id="mytable" class="table table-responsive table-striped table-bordered" cellspacing="0"
                       width-="100%">

                    <tbody>

                    <?php
                    foreach ($result as $row) {
                        if ($row->active == 1) {
                            foreach ($countries as $country) {
                                if ($country->id == $row->country) {
                                    if ($this->session->userdata('language') == 3) {
                                        $ccountry = $country->ro_name;
                                    } else if ($this->session->userdata('language') == 2) {
                                        $ccountry = $country->ru_name;
                                    } else {
                                        $ccountry = $country->name;
                                    }
                                }
                            }
                            $time_sbs = substr($row->time, 0, 5);
                            echo '<tr ">
                        <td width="20%">' . $row->name . '</td>
                        <td width="10%">' . $row->date . ' ' . $time_sbs . '</td>
                        <td width="10%">' . $row->registration_date . '</td>
                        <td width="10%">' . $ccountry . '</td>
                        <td width="10%">' . $row->city . '</td>
                        <td width="10%">' . $row->address . ' </td>
                        <td width="20%">' . $row->description . '</td>

我从数据库中抽取了日期

function get_tournaments()
{
    //data is retrive from this query
    $query = $this->ci->db->query("SELECT * FROM tournaments WHERE date > CURDATE() ORDER BY date");
    /*$query = $this->ci->db->query("SELECT * FROM tournaments");*/
    return $query;
}

function get_tournaments_finished()
{
    //data is retrive from this query
    $query = $this->ci->db->query("SELECT * FROM tournaments WHERE date < CURDATE() ORDER BY date");
    /*$query = $this->ci->db->query("SELECT * FROM tournaments");*/
    return $query;
}

我需要在视图中有一个表,但是在get参数的帮助下,我展示了锦标赛地图:

<?php echo base_url(); ?>tournaments?type=upcoming",
<?php echo base_url(); ?>tournaments?type=finished"

如何检查get参数类型

2 个答案:

答案 0 :(得分:0)

使用

$_GET['type'];

或者如果您愿意,可以使用method参数来知道类型

,而不是使用get
//something like this
//your url will be like this
base_url('tournament/upcoming'); or
base_url('tournament/finished');

//then your controller method will look like this
public function tournament(){
    $type = $this->uri->segment(3);
    //then fetch the data based on the type
}

我希望这对您有所帮助,如果您有任何问题,请告诉我们,以便我们对其进行整理。

答案 1 :(得分:0)

在Codeigniter中您可以使用

检查输入参数
$input_params=$this->input->get();// this will give you all parameters

$single_param=$this->input->get('name_of_the_parameter');// this will give you individual parameter