在View层,可以使用UrlHelper灵活构建需要的链接或访问路径,如:
$this->Url->build(['controller' => 'myController', 'action' => 'myAction', $myParams]);
而在Controller中,可以使用如下方式:
引入Router对象
use Cake\Routing\Router;
构建链接路径
Router::url([
'controller' => 'myController',
'action' => 'myAction',
$myParams
]);
构建特定的文件路径
Router::url('/someFolder/'.$someFileName);