urlManager in yii


urlManager in yii

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

以上代码读取url "abc "。"abc.co/ongSpcl/sp1"变为"abc.co/ongSpcl?"类别= sp1它的工作原理!但我的问题是,我想阅读上述格式的所有url,除了"abc.co/ongSpcl/index"

'ongSpcl/index'=>ongSpcl/index的规则(将右侧更改为您想要的任何路由)置于现有规则之前。Yii将执行它找到的第一个匹配项。

另外,供参考,您可以使用<category:'w+>匹配任何非空字符串的字母数字字符,如果这是您的意图。

从Yii Url中删除末尾的index,将显示类别动作从ongSpcl#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'));
    //
  }