2011-01-19 14 views
1

は、だから私は、次のように一致するZend_Controller_Router_Route_Hostnameを作成したいながら:Zend Frameworkのホスト名ルート:ルーティング無視してサブドメイン

  • example.com
  • www.example.com
  • stage.example.com
  • dev.example.com
  • andrew.dev.example.com
  • joe.dev.example.com

これらのすべてに一致するルートを作成する方法を理解できていないようです。 "example.com"の前には複数のサブドメインが存在する可能性があります。ここでは、私がこれまで持っているものです。

$hostnameRoute = new Zend_Controller_Router_Route_Hostname(':sandbox.:environment.example.com', array('controller' => 'events', 'event-id' => $eventId)); 

答えて

1

単一のホスト名のルートに複数のサブドメインを一致させることはできません。だからここにあなたがしなければならないものです:

$hostnameRoutes = array(
    new Zend_Controller_Router_Route_Hostname('example.com', array('controller' => 'events', 'event-id' => $eventId)), 
    new Zend_Controller_Router_Route_Hostname(':subdomain.example.com', array('controller' => 'events', 'event-id' => $eventId)), 
    new Zend_Controller_Router_Route_Hostname(':sandbox.dev.example.com', array('controller' => 'events', 'event-id' => $eventId)) 
); 

$homepageRoute =   new Zend_Controller_Router_Route_Static('',  array('action' => 'overview')); 
$eventPagesRoute =  new Zend_Controller_Router_Route(':action/*',  array('action' => 'overview')); 
$staticEventPagesRoute = new Zend_Controller_Router_Route('page/:page-id', array('action' => 'static-page')); 

foreach ($hostnameRoutes as $i => $hostnameRoute) { 
    $router->addRoute('sports_homepage' . $i,   $hostnameRoute->chain($homepageRoute)); 
    $router->addRoute('sports_event_pages' . $i,  $hostnameRoute->chain($eventPagesRoute)); 
    $router->addRoute('sports_static_event_Page' . $i, $hostnameRoute->chain($staticEventPagesRoute)); 
} 

注:ルートの名前は($iに注意し、それらを一意にするために連結されている)一意であることを確認してください。私はそれを初めて忘れてしまい、なぜそれが機能していないのか理解できませんでした。

1

あなたはより多くの、2つの選択肢を持つ非線形マッピングのための1つのルートができない、あなたは1、より多くを使用する必要がありますので、)各ドメインの目標を知りません例を挙げるのは難しいです。 両方それらrespecitveモジュールにマッピングされた(及びandreawとをパラメータとしてjoe)さexample.comwww.example.comがeaqualであり、デフォルトルートとstagedevの両方であると仮定すると(もちろんのルータに追加):

$stageRoute = new Zend_Controller_Router_Route_Hostname('stage.example.com', array('module' => 'stage'); 
$devRoute = new Zend_Controller_Router_Route_Hostname(':user.dev.example.com', array('module' => 'dev'); 

この(:module/:controller/:action)以下をマッピングします:

  • stage.example.comstage/index/indexから
  • dev.example.comすなわちdefault/index/index

からdev/index/index/user/joe

  • www.example.comからdev/index/index
  • joe.example.comへ:sudomainは他にstageと何をされた場合、デフォルトのパラメータでstageモジュールにアクセスしてください。 subdomaindevの場合はuserdevモジュールに移動します。それ以外の場合は、デフォルトのzendルートを使用します。
    ホスト名ルーターがどのパスにも一致するように注意してください。したがって、おそらく、その背後のパスと別のルートを一致させ、chain routerを使用する必要があります。

    $stageRoute = new Zend_Controller_Router_Route_Hostname('stage.example.com', array('module' => 'stage'); 
    $pathRoute = new Zend_Controller_Router_Route(':revision', array('controller' => 'browse')); 
    $stageRoute->chain($pathRoute); 
    

    stage/browse/index/revision/5434stage.example.com/5434をマッピングしたい:これは次のようになりますステージルートの

  • 関連する問題