CodeIgniter - 关闭控制器函数调用?
我只是想加载控制器而不是调用基于 URI 的函数,这样我就可以根据以下片段生成页面。 如何更改默认行为来执行此操作? 例如。
example.com/class/function/ID >>> example.com/class/ID/ID
我以为我需要做的就是在 config.php 添加:
$route['find/(:any)/(:any)'] = "find/$1/$2";
但这给了我一个 404。
example.com/find/item/location
class Find extends CI_Controller {
private $s1;
private $s2;
function __construct()
{
parent::__construct();
}
function index()
{
$this->s1 = $this->uri->segment(2);
$this->s2 = $this->uri->segment(3);
$this->makePage();
}
function makePage()
{
echo 'Page about ' . $this->s1 . 'in ' . $this->s2;
//Get Data ($s1 & $s2)
//Load View
}
}
I simply want to load the controller and not call a function based on the URI, so that I can then generate the page based on the following segments. How do I change the default behaviour to do this? eg.
example.com/class/function/ID >>> example.com/class/ID/ID
I thought all I needed to do was in config.php add:
$route['find/(:any)/(:any)'] = "find/$1/$2";
but this gives me a 404.
example.com/find/item/location
class Find extends CI_Controller {
private $s1;
private $s2;
function __construct()
{
parent::__construct();
}
function index()
{
$this->s1 = $this->uri->segment(2);
$this->s2 = $this->uri->segment(3);
$this->makePage();
}
function makePage()
{
echo 'Page about ' . $this->s1 . 'in ' . $this->s2;
//Get Data ($s1 & $s2)
//Load View
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想通了,需要添加另一个函数来调用(findit);
我发现这篇文章非常有帮助:CodeIgniter:使用 URL 定向到函数段
figured it out, needed to add another function to call (findit);
this post I found was very helpful: CodeIgniter: Directing to functions with a URL segment