dongmouhao7438 2014-02-26 01:26
浏览 41
已采纳

Laravel 4中的外墙问题

Sorry for the English, but I am using the google translator. First of all I leave my code:

FtpServiceProdiver.php

<?php namespace Jaimemse\Ftp;

use Illuminate\Support\ServiceProvider;

class FtpServiceProvider extends ServiceProvider {

protected $defer = false;

public function boot()
{
    $this->package('jaimemse/ftp');
}

public function register()
{
    $this->app->bind('ftp', function()
    {
        return new Ftp;
    });
}

public function provides()
{
    return array();
}
}

Ftp.php (the class)

<?php namespace Jaimemse\Ftp;

class Ftp {

public function hello()
{
    return 'hola';
}
}

Facades/Ftp.php (Facade)

<?php namespace Jaimemse\Ftp\Facades;

use Illuminate\Support\Facades\Facade;

class Ftp extends Facade {

    protected static function getFacadeAccessor() { return 'ftp'; }

}

app.php

'Jaimemse\Ftp\FtpServiceProvider',
'Ftp' => 'Jaimemse\Ftp\Facades\Ftp',

If instead of that Facade put this, if it works:

'Ftp' => 'Jaimemse\Ftp\Ftp',

The problem I have is that when using the alias in the file app.php seeks Ftp class in the folder Facades/Ftp.php

Call to undefined method Jaimemse\Ftp\Facades\Ftp::hello()

Someone can help me? Thanks!

  • 写回答

3条回答 默认 最新

  • doumei9832 2014-02-26 20:58
    关注

    I fixed it by adding in register method:

    FtpServiceProvider.php

    public function register()
    {
        $this->app->bind('ftp', function()
        {
             return new Ftp;
        });
    
        $this->app->booting(function() 
        { 
            $loader = \Illuminate\Foundation\AliasLoader::getInstance(); 
            $loader->alias('Ftp', 'Jaimemse\Ftp\Ftp'); 
        }); 
    }
    

    Ftp.php

    class Ftp {
    
        public function hello()
        {
            return 'hello';
        }
    
    }
    

    App.php

    'Jaimemse\Ftp\FtpServiceProvider',
    

    I have not added any app.php alias in the file. I deleted Facade file.

    Now I can do things like:

    Ftp::hello();
    

    Hope that helps someone. Thank you!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等