2011-10-09 62 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')); 
    // 
    }