ルートを工夫する必要があるだけです: http://ellislab.com/codeigniter/user-guide/general/routing.html
すべてのトラフィックをキャッチして を指すようにルートを設定するとdirectory/listing
、listing
メソッド内で手動で URL セグメントにアクセスできます。例えば:
// application/config/routes.php
$route[':any'] = "directory/listing";
/**
you might have to play with this a bit,
I'm not sure, but you might need to do something like:
$route[':any'] = "directory/listing";
$route[':any/:any'] = "directory/listing";
$route[':any/:any/:any'] = "directory/listing";
$route[':any/:any/:any/:any'] = "directory/listing";
*/
// application/controllers/directory.php
function listing()
{
// docs: http://ellislab.com/codeigniter/user-guide/libraries/uri.html
$state = $this->uri->segment(1);
$city = $this->uri->segment(2);
$unique_id = $this->uri->segment(3);
$unique_page_name = $this->uri->segment(4);
// then use these as needed
}
または、おそらくそうであるように、他のコントローラーとメソッドを呼び出すことができる必要があります-
コントローラを指すように URL を変更してから、一覧表示を行うことができます -
したがって、あなたのURLは次のようになります。
asdf.com/directory/{state}/{city}/{unique_id}/{unique-page-name}/
ルートは次のようになります。
$route['directory/:any'] = "directory/listing";
次に、メソッドの uri セグメントを更新してlisting
、2 番目、3 番目、4 番目、および 5 番目のセグメントと一致させる必要があります。
このようにして、別のコントローラーを呼び出すことができ、カスタムルートによってキャッチされることはありません:
asdf.com/contact/ --> would still access the contact controller and index method
アップデート
また、創造性を発揮し、正規表現を使用して、最初の uri セグメントで状態名を持つ URL をキャッチすることもできます。次に、それらをプッシュするdirectory/listing
と、他のすべてのコントローラーが引き続き機能directory
し、URL にコントローラーを追加する必要がなくなります。このようなものがうまくいくかもしれません:
// application/config/routes.php
$route['REGEX-OF-STATE-NAMES'] = "directory/listing";
$route['REGEX-OF-STATE-NAMES/:any'] = "directory/listing"; // if needed
$route['REGEX-OF-STATE-NAMES/:any/:any'] = "directory/listing"; // if needed
$route['REGEX-OF-STATE-NAMES/:any/:any/:any'] = "directory/listing"; // if needed
/**
REGEX-OF-STATE-NAMES -- here's one of state abbreviations:
http://regexlib.com/REDetails.aspx?regexp_id=471
*/