dongshi3818 2014-09-25 14:47
浏览 34

Laravel Package开发简单的功能不起作用

Sorry for the bad title, but I had no idea to give a good title for my problem.

I created a package with the workbench. And now I have a package. Let's say strernd/mypkg Inside the workbench directory Strernd/Mypkg I've got following code: http://laravel.io/bin/oNzoa

Why does Mypkg::test()work and $mypkg = new Mypkg(); $mypkg->test(); not? (Inside my app) The error is Call to undefined method Strernd\Mypkg\Facades\Mypkg::test()Call to undefined method Strernd\Mypkg\Facades\Mypkg::test()

I think I'm not understanding some basic principles of PHP here. I'm more like a copy&paste / try&error "developer", but it works out well in most cases.

  • 写回答

1条回答 默认 最新

  • dongtun1872 2014-09-25 14:58
    关注

    When using it the 'static' way, Laravel is accessing the facade you wrote and instantiating the underlying class, then calling the method on that instance. When you are calling the test method with new Mypkg, you are actually instantiating the facade class, and not the underlying class. That facade class does not have a test method on it, hence the error.

    Try it like this:

    use Strernd\Mypkg as MypkgActual;
    
    $mypkg = new MypkgActual;
    $mypkg->test();
    

    I believe that, because your facade and actual class implementation have the same exact class name, you're running in to a pseudo-class name conflict with Laravel's facade system winning out. You can also try changing the name of your facade to MypkgFacade.

    评论

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像