2011-10-09 77 views
0
'urlManager'=>array(
      'urlFormat'=>'path', 
      'rules'=>array(
       'ongSpcl/<category:.*?>'=>'ongSpcl/index', 
      ), 
     ), 

上面的代碼讀取URL「abc.co/ongSpcl/sp1」爲「abc.co/ongSpcl?category=sp1 它的工作原理! 但我的問題是,我想讀的所有URL中除了上述格式「abc.co/ongSpcl/ 指數urlManager在警予

回答

0

把一個規則'ongSpcl/index'=>ongSpcl/index(改變任何你想要的路線右側)之前,您現有的規則。Yii的將執行第一個匹配它發現。

另外,fyi,你可以使用<category:\w+>如果這是您的意圖,請匹配任何非空字符的字母數字字符

+0

感謝您的答覆BT答案沒有解決我的目標。我提供的代碼是做gr8(它讀取abc.co/ongSpcl/category1爲abc.co/ongSpcl?category=category1)bt我想爲「index」添加一個異常,所以dat abc.co/ongSpcl/index將會b閱讀爲abc.co/ongSpcl/index – iThink

+0

我仍然把你引向我的答案。如果你發佈完整的urlManager代碼,這可能會有所幫助。 – ldg

0

去除Yii的網址,從ongSpcl#index別的東西改變節目類別動作後index,再加入'/ongSpcl' => 'ongSpcl/index'

'urlManager'=>array(
    'urlFormat'=>'path', 
    'rules'=>array(
    '/ongSpcl' => 'ongSpcl/index', 
    '/ongSpcl/<category:.*?>'=>'ongSpcl/show', 
), 
), 

存根測試路線

class RoutingTest extends CTestCase { 
    public function createUrl($route, $params=array()) { 
    $url = explode('phpunit', Yii::app()->createUrl($route, $params)); 
    return $url[1]; 
    } 

    public function testCorrectRoutes() { 
    $this->assertEquals('/ongSpcl', $this->createUrl('ongSpcl/index')); 
    $this->assertEquals('/ongSpcl/sp1', $this->createUrl('ongSpcl/show', array('category' => 'sp1')); 
    // 
    }