[英]CodeIgniter URL issue
I am having difficulty getting the correct URL when I call a method to load a view. 调用加载视图的方法时,我很难获得正确的URL。
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) 这是我的观点:(请注意,该观点不是从
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>
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? 因此,在我的控制器中,我有两个函数,
qs
函数自己单独工作,因此可以在视图中调用并提供以下URL myController/qs/1
但是当我使用post函数时,我会得到一个类似myController/post
的URL,因此我的问题是如何使我的网址像第一个示例一样?
尝试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 这应该与您在视图中使用的方式相同
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.