0
我正在製作一個迷你網上商店系統,供您練習,因此您可以動態創建多個網上商店。Kohana 3,檢測動態uri
目前,我有這樣的:
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具有動態路由。
如果這是一個網上商店匹配,它會帶您到網上商店的索引。 - 工作正常。
現在,只有當你在網上商店的root uri上登陸時,例如「/ myWebshop」纔有效。
因爲我有兩個控制器,一個名爲「店」等所謂的「客戶」,我想他們通過/ myWebshop /店/動作和/ myWebshop /客戶進行訪問/動作所有網店
的這裏的問題在於「myWebshop」是動態的,「商店」控制器或「客戶」控制器中的動作函數方法也是動態的。
我該如何寫兩條路線,這是動態的?
這是多遠我就來了:
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'
);
}
}
我不知道在這之後做什麼,我怎麼能知道創建動態路由,並開始直接指向用戶?