我为我的网站自定义了基本路径,如下所示:
Router::scope('/', function (RouteBuilder $routes) {
//$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
//My custom base path
$routes->connect('/', ['controller' => 'Posts', 'action' => 'index', 'home']);
//Connect the rest of PagesController URLs
$routes->connect('/pages/*', ['controller' => 'Pages', 'action' => 'display']);
//I don't quite understand what this line does
$routes->fallbacks(DashedRoute::class);
});
然后,当我像这样在控制器内部重定向时,URL 是正确的:
return $this->redirect(['controller' => 'Posts', 'action' => 'view', $data['post_id']]);
//output:
// localhost/jayblog/posts/view/2
但是对于外部链接 和WWWROOT
,它会返回错误的链接:
<li><a href="https://www.example.com" target="_blank" title="Twitter">LINK</a></li>
//output is wrong:
// localhost/jayblog/https://www.example.com
<?= $this->Html->image(WWW_ROOT.DS.'files'.DS.$photos[$i]->file_name); ?>
//output:
// jayblogD:\path\to\file.PNG
任何人都请建议我如何解决这个问题。谢谢!