dswy34539 2018-03-03 05:38
浏览 62
已采纳

Codeigniter:获取页面的URI段并将其添加到其重定向页面的URL中

So I have these 2 pages IF the URL of page1 is: http://localhost/project/page1/page1/5

And there's a link in that page that redirects to page2 with the URL:

http://localhost/project/page2/page2/2
(its 3rd segment - 2 is from dropdown value selected)

Is it possible to make the redirected page - page2 with a URL like this: http://localhost/project/page2/page2/5/2

-so that I could do something with page1's value, like querying dynamically in the database.

VIEW in page1:

<div class="form-group form-inline">
  <select id="p2_val">

      <?php 
          foreach($v_p2 as $row) {
      ?> 
      <option 
          value="<?php  echo base_url('page2/page2/').$row->p2_val;?>">
          <?php echo $row->p2_num; ?>
      </option>
      <?php }  ?> 

  </select>

      <input  class="SubmitButton" type="submit" 
      name="SUBMITBUTTON" value="Submit" />
</div>

Controller in page1:

class Page1 extends CI_Controller{

     public function __construct()
        {
            parent::__construct(); 
            $this->load->model('page1_model');

        }

    public function page1(){
        if($this->session->userdata('logged')){

            $this->load->model('page1_model');

            $data["v_p2"] = $this->page1_model->v_p2($this->session->userdata('user_id'));

            $this->load->view('pages/page1', $data);

            $this->load->view('templates/footer');

        }

    }

Controller of page2:

class Page2 extends CI_Controller{

     public function __construct()
        {
            parent::__construct(); 
            $this->load->model('page2_model');

        }

    public function page2(){
        if($this->session->userdata('logged')){

            $this->load->model('page2_model');

            $data["get_p2"] = $this->page2_model->get_p2($this->session->userdata('user_id'));

            $this->load->view('pages/page2', $data);

            $this->load->view('templates/footer');

        }

    }
  • 写回答

2条回答 默认 最新

  • dongpao9437 2018-03-03 09:11
    关注

    I changed view of page1 into:

      <option 
          value="<?php  echo base_url('page2/page2/').$row->p1_val.'/'.$row->p2_val;?>">
          <?php echo $row->p2_num; ?>
      </option>
    

    No change in the controllers, just worked around with models by using:

    $this->uri->segment();
    

    - Most changes were then in the db queries I made.
    - Since I added additional segment in page2, I added " ../ " to the paths of the assets.

    sample - model for page2:

       function v_p2($data){
            $p1_val = $this->uri->segment(3);
            $p2_val = $this->uri->segment(4); 
    
             //DO smth with $p1_val & $p2_val
             //These values were used for querying
    
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃