CodeIgniter - 关闭控制器功能调用?

时间:2011-02-10 12:27:30

标签: php codeigniter codeigniter-routing

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

1 个答案:

答案 0 :(得分:3)

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

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

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

我发现此帖非常有用:CodeIgniter: Directing to functions with a URL segment