0

練習用にミニ 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'
    );
}
}

この後どうすればよいかわかりません。どうすれば動的ルートを作成し、ユーザーを直接指し始めることができますか?

4

1 に答える 1

0

の場合と同じ方法で、URL からコントローラーとアクション部分を取り出します$uri

return array(
        'controller' => !empty($uri[1]) ? $uri[1] : 'some_default_controller',
        'action' => !empty($uri[2]) ? $uri[2] : 'some_default_action',
        'directory' => 'shop' // OR $uri[x] if it's also supposed to be dynamic
    );
于 2013-06-25T13:09:54.243 に答える