2011-02-10 18 views
1

コントローラをロードして、URIに基づいて関数を呼び出さず、次のセグメントに基づいてページを生成するだけです。 これを行うにはどうすればデフォルトの動作を変更できますか?など。CodeIgniter - コントローラの関数呼び出しをオフにしますか?

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 
} 
} 

答えて

3

これを見つけ出し、別の関数を呼び出して(findit)呼び出す必要がありました。

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

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

私が見つけたこの記事は非常に有用だった:CodeIgniter: Directing to functions with a URL segment

関連する問題