質問

I am trying to set up a Facade for a custom built class in laravel-4. However, when I try to load my website I get an error which reads

Class 'PlaneSaleing\ResizerServiceProvider' not found

I have followed the tutorial here: http://fideloper.com/create-facade-laravel-4

My custom class is called Resizer.php and is saved in laravel\app\library\ and looks like this:

<?php

namespace PlaneSaleing;

class Resizer {
    // My custom methods
}

I have then created a Facade called ResizerFacade.php, saved in the same folder, and it looks like this:

<?php

namespace PlaneSaleing\Facades;

use Illuminate\Support\Facades\Facade;

class Resizer extends Facade {

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

}

Thirdly, I have created a ResizerServiceProvider.php file and saved it in the same folder, which looks like:

<?php

namespace PlaneSaleing;

use Illuminate\Support\ServiceProvider;

class ResizerServiceProvider extends ServiceProvider {

    public function register()
    {
        // Register 'resizer' instance container to our UnderlyingClass object
        $this->app['resizer'] = $this->app->share(function($app)
        {
            return new Resizer;
        });

        // Shortcut so developers don't need to add an Alias in app/config/app.php
        $this->app->booting(function()
        {
            $loader = AliasLoader::getInstance();
            $loader->alias('Resizer', 'PlaneSaleing\Facades\Resizer');
        });
    }
}

Finally, I have added the following line to the 'providers' => array (...) in laravel/config/app.php file

'PlaneSaleing\ResizerServiceProvider',

Any help, much appreciated

役に立ちましたか?

解決

You have to add app/library to you composer autoload path, then regenerate autoloader with artisan dump-auto.

The second error you're getting (Class 'PlaneSaleing\AliasLoader' not found) is because the class ResizerServiceProvider is in the PlaneSaleing namespace and this class try to call AliasLoader which is not in the same namespace.

You just have to add a \ in front of AliasLoader to specify that it's in the main namespace instead of the current namespace.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top