Zim*_*bor 1 php cakephp cakephp-2.3
如果我在浏览器中键入:" http://examplepage.com/gallery/examplecagegory/1-test-picture.jpg ".
转到webroot:"app/webroot/gallery/pictures/1.jpg"
我试过了:
Router::connect('/gallery/:slug_category/:id-:slug.:extension',
array('webroot/gallery/pictures'),
array(
'pass' => array('id', 'slug'),
'id' => '[0-9]+'
)
);
Run Code Online (Sandbox Code Playgroud)
但我坚持在第二排...: - /
这不是你可以用路由做的事情,正如书中所述:
路由是将URL映射到控制器操作的功能.
图像资源不是控制器动作.您应该只使用.htaccess文件中的普通RewriteRule app/webroot来重写所有调用.像这样的东西应该做的伎俩:
RewriteRule ^gallery/[a-z]+/([0-9]+)-[a-z-]+\.([a-z]{3})$ /gallery/pictures/$1.$2
Run Code Online (Sandbox Code Playgroud)
请注意,HtmlHelper app/webroot/images默认情况下会搜索文件夹中的图像,因此您需要使用绝对URL(使用前导斜杠为所有图像调用添加前缀)来使用重写的路径,例如这不起作用:
$this->Html->image('gallery/examplecategory/1-test-picture.jpg');
Run Code Online (Sandbox Code Playgroud)
您应该使用此代替:
$this->Html->image('/gallery/examplecategory/1-test-picture.jpg');
Run Code Online (Sandbox Code Playgroud)