有一个视图和一个控制器,使用get参数,必须通过链接更改路径。所以最终结果如下:
即将到来 - > http://mywebsite.com/tournaments?type=upcoming
完成 - > http://mywebsite.com/tournaments?type=finished
答案 0 :(得分:0)
这是将处理您的GET变量的控制器
Controller
<?php
class Demo_controller extends CI_Controller
{
public function demo($id)
{
echo $id; //the id which you will get in URL string
}
}
?>
查看您将传递变量的文件
<?php
$id = "1";//dyanmic id which will be pased with the form
echo form_open('demo/demos-function'.$id);
//in between your code
echo form_close
?>
Routes
Inside routes.php
$route['demo/demos-function/(:any)] = Demo_controller/demo/$1
无需更改$ 1,它将解释它具有URL参数的路由。 所以最终你的链接将是
https://localhost/demo/demos-function/1
https://localhost/demo/demos-function/2
答案 1 :(得分:0)
在Codeigniter Url中这样:
即将到来 - &gt; http://mywebsite.com/controller/method/upcoming
完成 - &gt; http://mywebsite.com/controller/method/finished
public function method_name()
{
$type = $this->uri->segment(3); // third level value of URL - Segment(1) is controller and followed by method and query string
if($type == 'upcoming')
{
echo $type;
$this->load->view('upcoming');
}
else
{
echo $type;
$this->load->view('finished');
}
}