Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将下拉菜单中的值分配给控制器中的变量,该变量用于Codeigniter中的模型_Php_Mysql_Sql_Codeigniter - Fatal编程技术网

Php 将下拉菜单中的值分配给控制器中的变量,该变量用于Codeigniter中的模型

Php 将下拉菜单中的值分配给控制器中的变量,该变量用于Codeigniter中的模型,php,mysql,sql,codeigniter,Php,Mysql,Sql,Codeigniter,我试图通过从下拉菜单中选择一个选项来动态查询我的数据库,并使用GET方法将其值分配回控制器中的一个变量,然后在模型中使用该变量,但我不确定如何执行该操作 我的代码如下 视图-保留下拉菜单 <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Latest Hurling Fixtures<b class="caret"></b>

我试图通过从下拉菜单中选择一个选项来动态查询我的数据库,并使用GET方法将其值分配回控制器中的一个变量,然后在模型中使用该变量,但我不确定如何执行该操作

我的代码如下

视图-保留下拉菜单

  <li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Latest Hurling  Fixtures<b class="caret"></b></a>

   <ul class="dropdown-menu">

     <li><a href="<?php echo site_url('user/get_fixtures?fixture_type=Hurling&fixture_level=Roinn 1A') ?>">Roinn 1A</a></li>

     <li class="active"><a href="<?php echo site_url('user/get_fixtures?fixture_type=Hurling&fixture_level=Roinn 1B') ?>">Roinn 1B</a></li>

     <li><a href="<?php echo site_url('user/get_fixtures?fixture_type=Hurling&fixture_level=Roinn 2A') ?>">Roinn 2A</a></li>

     <li><a href="<?php echo site_url('user/get_fixtures?fixture_type=Hurling&fixture_level=Roinn 2B') ?>">Roinn 2B</a></li>
    </ul> 
  </li>
然后我想在查询数据库的模型中使用这些变量

模型


运行此命令时,会出现未定义的变量错误。

如果在配置文件中启用它:$config['enable\u query\u strings']=TRUE

您可以像这样使用get()方法

$this->input->get('param_name');
所以在你的例子中可能是

$fixture_round = $this->input->get('fixture_type');

经过更多的挖掘,我发现以下几点对我很有用

步骤1-更改应用程序文件夹中配置文件中的URI协议

换成这个

$config['uri_protocol'] = 'AUTO';
对此

$config['uri_protocol'] = "PATH_INFO";
步骤2-将以下内容添加到控制器中的构造方法

    //Allow querystrings for this constructor

    parse_str($_SERVER['QUERY_STRING'],$_GET);
步骤3-我在视图中的下拉菜单中使用了以下代码-下拉菜单项从我的控制器调用一个名为“get_fixtures”的方法,该方法称为“users”

看法

第4步-最后,在查询数据库之前,在模型中设置变量

模型


它非常适合我:)

您好,谢谢您的回复-我尝试了您的要求,但它的效果是禁用了我在代码其他地方使用的图像路径。他们使用站点URL。还有,我仍然有未定义的变量错误。如果是这样的话,为什么不为参数使用url段而不是url参数呢?或者更好…只是创建一个表单而不是锚,然后通过POST发送它们,然后完全跳过URL?如果您确实需要使用锚定标记,只需使用jquery或其他方法发送POST变量即可。您不需要将$fixture\u type和$fixture\u level传递给模型,也不需要启用任何东西就可以使用$this->input->get()而不是_get(使用输入类来增加安全性)。fixtures()模型中的函数应该接受两个参数fixture($fixture\u type,$fixture\u level)&控制器应该调用提供上述参数的模型方法。
$config['uri_protocol'] = "PATH_INFO";
    //Allow querystrings for this constructor

    parse_str($_SERVER['QUERY_STRING'],$_GET);
<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown">Latest Hurling Fixtures<b class="caret"></b></a>
  <ul class="dropdown-menu">

   <li><a href="<?php echo site_url('user/get_fixtures?fixture_type=Hurling&fixture_level=Roinn 1A') ?>">Roinn 1A</a></li>
   <li><a href="<?php echo site_url('user/get_fixtures?fixture_type=Hurling&fixture_level=Roinn 1B') ?>">Roinn 1B</a></li>
   <li><a href="<?php echo site_url('user/get_fixtures?fixture_type=Hurling&fixture_level=Roinn 2A') ?>">Roinn 2A</a></li>
   <li><a href="<?php echo site_url('user/get_fixtures?fixture_type=Hurling&fixture_level=Roinn 2B') ?>">Roinn 2B</a></li>
    <li><a href="<?php echo site_url('user/hurl_all_ireland') ?>">All Ireland Championship</a></li>  
   </ul> 
</li>
public function get_fixtures()
{

 //I used the commented out lines below to test that I was getting a value back from the  GET in my dropdown menu 

 //$fixture_type = $_GET['fixture_type'];
 //$fixture_level = $_GET['fixture_level'];

 //echo $fixture_type;
//echo $fixture_level;*/

 $data['title']= 'Hurling';
 $this->load->model('fixture_model');

 $data['results'] = $this->fixture_model->fixtures();

 $this->load->view('include/header',$data);
 $this->load->view('pages/hurling_view.php', $data);
 $this->load->view('include/footer',$data);

}
function fixtures() 

    {
        //Query the fixture table for every record and row

        // Set the variables to the values selected from the drop down menu
        $fixture_type = $_GET['fixture_type'];
        $fixture_level = $_GET['fixture_level'];  

        $fixture_round = "Round 3";
        //$fixture_level = "Roinn 1A";
        $results = array();

        $this->db->select('tf.*, t1.*, fixture.*, venue.*, t2.team_id as team_id_2, t2.team_name as team_name_2, t2.team_logo as team_logo_2, fixture_text, fixture_type, fixture_comp, fixture_date, fixture_level');
        $this->db->from('team_has_fixture as tf');

        $this->db->join('team as t1', 't1.team_id = tf.team_team_id');
        $this->db->join('team as t2', 't2.team_id = tf.team_team_id2');
        $this->db->join('fixture', 'tf.fixture_fixture_id = fixture.fixture_id');
        $this->db->join('venue', 'fixture_venue_id = venue.venue_id');
        $this->db->where('fixture_type', $fixture_type);
        $this->db->where('fixture_round', $fixture_round);
        $this->db->where('fixture_level', $fixture_level);
        $query = $this->db->get();

        //echo $this->db->last_query(); // Used this to see what my latest query contained

        if($query->num_rows() > 0) 
        {
         $results = $query->result();
        }

        //var_dump($query->result()); // used this to see that the results of my query contained

        return $results;         
    }