練習用にミニ Web ショップ システムを作成しているので、複数の Web ショップを動的に作成できます。
私は現在これを持っています:
Route::set('dynamic_routes', function($uri)
{
$webshop = DB::select()->from('webshops')
->where('uri', '=', $uri)
->execute()
->get('id', 0);
// Check if there is a match
if ($webshop > 0)
{
define('WEBSHOP_ID', $webshop);
return array(
'controller' => 'shop',
'action' => 'index',
'directory' => 'shop'
);
}
}
);
これで処理されるので、データベースで URI を検索して動的ルートを作成できます。
一致する Web ショップがある場合は、その Web ショップのインデックスに移動します。- 正常に動作します。
これは、「/myWebshop」などの Web ショップのルート URI に到達した場合にのみ機能します。
すべてのウェブショップに対して、「shop」と呼ばれるコントローラーと「customer」と呼ばれるコントローラーの 2 つのコントローラーがあり、/myWebshop/shop/action および /myWebshop/customer/action からアクセスできるようにしたいと考えています。
ここでの問題は、「myWebshop」が動的であり、「shop」コントローラーまたは「customer」コントローラーのアクション関数メソッドも動的であることです。
動的な 2 つのルートを作成するにはどうすればよいですか?
これは私がどこまで来たかです:
if(strpos($uri, '/'))
{
// If we have a /, and [1] isn't empty, we know that the user looks for subpage?
$expl = explode('/', $uri);
if(!empty($uri[1]))
{
// Set the uri to the first part, in order to find the webshop?
$uri = $uri[0];
}
$webshop = DB::select()->from('webshops')
->where('uri', '=', $uri)
->execute()
->get('id', 0);
// Check if there is a match
if ($webshop > 0)
{
define('WEBSHOP_ID', $webshop);
return array(
'controller' => 'shop',
'action' => 'index',
'directory' => 'shop'
);
}
}
この後どうすればよいかわかりません。どうすれば動的ルートを作成し、ユーザーを直接指し始めることができますか?