1

我只是想加载控制器而不是基于 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 
}
}
4

1 回答 1

3

想通了,需要添加另一个函数来调用(findit);

$route['find/(:any)/(:any)'] = "find/findit/$1/$2";

function findit()
{
    $this->makePage();
}

我发现这篇文章很有帮助:CodeIgniter: Directing to functions with a URL segment

于 2011-02-10T13:02:20.753 回答