【问题标题】:CodeIgniter URL issueCodeIgniter URL 问题
【发布时间】:2013-12-31 15:36:39
【问题描述】:

当我调用加载视图的方法时,我很难获得正确的 URL。

这是我的控制器:

public function post() {
        $title = $this->input->post('title');
        $data = $this->p_Model->post($title);
        $this->qs($data);
    }

public function qs($id){
        $title = $this->s_Model->getTitle($id);
        $result = $title->result();
        $this->load->view('q_View', array('results' => $result));
    }

这是我的观点:(注意这个视图不是从qs 函数加载的视图,而是调用qs 函数的视图)

<html>
<body>
<table>
<?php
        if (isset($qs)) {
            foreach ($qs as $row) {
                $id = $row->qID;
                echo '<a href="'.site_url('myController/qs/'.$id).'">';
                echo $row->title;
                echo "<br>";
            }
        }
?>
</table>
</body>
</html>

所以在我的控制器中我有两个函数,qs 函数单独工作,因此可以在视图中调用并提供以下 url myController/qs/1 但是当我使用 post 函数时,我得到一个这样的 url @ 987654327@ 所以我的问题是如何让我的网址像第一个示例一样?

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    而不是使用该行:

    $this->qs($data);
    

    您可以使用重定向:

    redirect('/mainController/qs/'.$data);
    

    这应该与您在视图中使用的方式相同

    【讨论】:

      【解决方案2】:

      试试base_url,你也可以使用current_url()返回当前正在查看的页面的完整URL(包括片段)。

      echo '<a href="'.base_url('myController/qs/'.$id).'">';
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-11-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-09
        相关资源
        最近更新 更多