使用Yii的Url映射问题

使用Yii的Url映射问题,url,yii,mapping,Url,Yii,Mapping,我有用于静态资源的控制器,例如图像 class ResourceController extends Controller { public function actionImage($fname) { $file = Yii::app() -> params['baseFilesPath'] . $fname; if (file_exists($file)) { header("Content-Type: image/jpeg"); he

我有用于静态资源的控制器,例如图像

class ResourceController extends Controller {

public function actionImage($fname) {
    $file = Yii::app() -> params['baseFilesPath'] . $fname;
    if (file_exists($file)) {
        header("Content-Type: image/jpeg");
        header("Accept-Ranges: bytes");
        header("Content-Length: " . filesize($file));
        // header("Content-Disposition: attachment; filename=" . $fname);
        readfile($file);
    }
}
我有这个控制器的url映射:

urlManager'=>array(
        'urlFormat'=>'path',
        'rules'=>array(
            'resources/<fname:\w+>' => 'resource/image',
            'product/<name:\w+>/<id:\d+>' => 'catalog/product', 
            '<controller:\w+>/<id:\d+>'=>'<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
            '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        ),
    ),
但控制员没有打电话

你能帮我吗?我认为我的regexp是错误的。

由于您的
fname
参数中有一个点,并且点不是(
\w
),您只需尝试以下规则:

'resources/<fname>' => 'resource/image',
“资源/”=>“资源/图像”,

如果省略了ParamPattern,则表示该参数应 匹配除斜杠以外的任何字符/

'resources/<fname>' => 'resource/image',