dtzhfb4869 2017-04-11 12:08
浏览 27
已采纳

在Cakephp 3中找不到“路由器”类

I am upgrading my cakephp version from 2.6.7 to 3.3.4. The following code was properly working to refer the home url:

<?php echo Router::url('/', true); ?>

But this not working in cakephp 3.3.4 and it shows the following error message:

Error: Class 'Router' not found 

Which I missed? Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dsjlqkbpn029473708 2017-04-11 15:34
    关注

    You need to make yourself comfortable with PHP namespaces. The Router class lives in the Cake\Routing namespace, hence you have to use either:

    \Cake\Routing\Router::url()
    

    or import the class:

    use Cake\Routing\Router;
    

    That being said, in your views you may want to use the Url helper instead (as mentioned by Jacek B Budzynski in the comments), in order to avoid the hard dependency on the Router class:

    $this->Url->build('/', true)
    

    See also

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错