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:URLセグメントを持つ関数への指示

于 2011-02-10T13:02:20.753 に答える