こんにちは私はそのようなものを作るつもりはありません。
http://example.com/ - メインコントローラー
http://example.com/rules/ - データベースからコンテンツを取得するメイン コントローラー。存在しない場合は 404 ページを返します。(大丈夫です、問題ありません。)
しかし、application/controlles/rules/ にサブフォルダーがある場合、Rules フォルダーの Main Contorller にリダイレクトしたいと考えています。
この次のコードは問題を解決できますが、どのように実現するのかわかりません。routes.php で:
$route['default_controller'] = "main";
$route['404_override'] = '';
$dirtest = $route['(:any)'];
if (is_dir(APPPATH.'controllers/'.$dirtest)) {
$route['(:any)'] = $dirtest.'/$1';
} else {
$route['(:any)'] = 'main/index/$1';
}
わかりました、私が持っているもの:
コントローラー/main.php
class Main extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('main_model');
}
public function index($method = null)
{
if (is_dir(APPPATH.'controllers/'.$method)) {
// Need re-rout to the application/controllers/$method/
} else {
if ($query = $this->main_model->get_content($method)) {
$data['content'] = $query[0]->text;
// it shows at views/main.php
} else {
show_404($method);
}
}
$data['main_content'] = 'main';
$this->load->view('includes/template', $data);
}
}
再度更新(routes.php):だから、私が検索したもののようです(作業例):
$route['default_controller'] = "main";
$route['404_override'] = '';
$subfolders = glob(APPPATH.'controllers/*', GLOB_ONLYDIR);
foreach ($subfolders as $folder) {
$folder = preg_replace('/application\/controllers\//', '', $folder);
$route[$folder] = $folder.'/main/index/';
$route[$folder.'/(:any)'] = $folder.'/main/$1';
}
$route['(:any)'] = 'main/index/$1';
しかし、次のようなものが完全に必要です。
http://example.com/1/2/3/4/5/6/...
- フォルダー「コントローラー」にサブフォルダー「1」がありますか?
- はい: フォルダー "1" にサブフォルダー "2" がありますか?
- いいえ: フォルダー「1」にはコントローラー「2.php」がありますか?
- いいえ: コントローラ "controllers/1/main.php" には関数 "2" がありますか?
- はい: http://example.com/1/2/ にリダイレクトします - ここで 3,4,5 - パラメータ..
次のような構造がある場合、それは本当に素晴らしいです:
http://example.com/blog/ - recent blog's posts
http://example.com/blog/2007/ - recent from 2007 year blog's posts
http://example.com/blog/2007/06/ - same with month number
http://example.com/blog/2007/06/29/ - same with day number
http://example.com/blog/web-design/ - recent blog's post's about web design
http://example.com/blog/web-design/2007/ - blog' posts about web design from 2007 years.
http://example.com/blog/current-post-title/ - current post
同じ興味深いhttp://codeigniter.com/forums/viewthread/97024/#490613を見つけました