简体   繁体   中英

CodeIgniter URL issue

I am having difficulty getting the correct URL when I call a method to load a view.

Heres my controller:

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));
    }

Heres my view:(note this view is not the view which gets loaded from the qs function, but one which calls the qs function)

<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>

So in my controller I have two functions, the qs function works separately by itself so can be called in the view and give the following url myController/qs/1 however when I use the post function I get a url like this myController/post so my question is how can I get my url to be like the first example?

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

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

Instead of using the line:

$this->qs($data);

You can use a redirect:

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

That should work in the same way that you have used in your view

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM