Laravel 4 - 扩展分页课程

时间:2013-06-12 06:43:23

标签: laravel laravel-4

有没有办法扩展Laravel 4的分页类?

我尝试了一些东西,但没什么好处......

我在这里:

PaginationServiceProvider.php     

class PaginationServiceProvider extends \Illuminate\Pagination\PaginationServiceProvider {
    /**
     * Indicates if loading of the provider is deferred.
     * @var bool
     */
    protected $defer = false;

    /**
     * Bootstrap the application events.
     * @return void
     */
    public function boot(){
        $this->package('thujohn/pagination');
    }

    /**
     * Register the service provider.
     * @return void
     */
    public function register(){
        $this->app['paginator'] = $this->app->share(function($app){
            $paginator = new Environment($app['request'], $app['view'], $app['translator']);
            $paginator->setViewName($app['config']['view.pagination']);
            return $paginator;
        });
    }

    /**
     * Get the services provided by the provider.
     * @return array
     */
    public function provides(){
        return array();
    }
}

Environment.php     

class Environment extends \Illuminate\Pagination\Environment {
    public function hello(){
        return 'hello';
    }
}

我用'Thujohn \ Pagination \ PaginationServiceProvider'替换'Illuminate \ Pagination \ PaginationServiceProvider',

当我拨打 $ test-> links()时,没关系

当我致电 $ test-> hello()时,它会失败

当我打电话给 Paginator :: hello()时没关系

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

除了Paginator::make()返回Paginator个实例,而不是Environment之外,一切都很好。

您应该将您的方法移至Paginator课程。

今天我发布了GH Paginator的扩展名。您可以将其作为参考desmart/pagination

进行检查