未找到 Laravel 类“AppModulesServiceProvider"?

Laravel Class #39;AppModulesServiceProvider#39; not found?(未找到 Laravel 类“AppModulesServiceProvider?)
本文介绍了未找到 Laravel 类“AppModulesServiceProvider"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们好,我是 Laravel 框架的新手.

Hello Friends I am new in Laravel framework.

我在 app 文件夹中创建模块目录.

i create modules directory in app folder.

然后我还在模块目录中创建 ServiceProvider.php 文件.

then i also create ServiceProvider.php file in modules directory.

我的文件结构喜欢.

appmodulesServiceProvider.php

这是ServiceProvider.php的代码.

This is code of ServiceProvider.php.

<?php 
namespace AppModules;

abstract class ServiceProvider extends IlluminateSupportServiceProvider {

public function boot() {
    if ($module = $this->getModule(func_get_args())) {
        $this->package("app/" . $module, $module, app_path() . "/modules/" . $module);
    }
}

public function register() {

    if ($module = $this->getModule(func_get_args())) {
        $this->app["config"]->package("app/" . $module, app_path() . "/modules/" . $module . "/config");

        // Add routes
        $routes = app_path() . "/modules/" . $module . "/routes.php";
        if (file_exists($routes))
        require $routes;
    }
}

public function getModule($args) {
    $module = (isset($args[0]) and is_string($args[0])) ? $args[0] : null;
    return $module;
}

}

然后我在模块目录中创建一个新的点目录.

Then i create a new points directory in modules directory.

并在 points 目录中创建 ServiceProvider.php 文件.

and also create ServiceProvider.php file in points directory.

这是ServiceProvider.php文件代码.

This is ServiceProvider.php file code.

<?php

namespace AppModulesPoints;

class ServiceProvider extends AppModulesServiceProvider {

public function register() {
parent::register("points");
}

public function boot() {
parent::boot("points");
}

}

然后我现在尝试加载项目,但出现错误.

Then now i try to load project i got error like.

Class 'AppModulesServiceProvider' not found 

 SymfonyComponentDebugExceptionFatalErrorException
…/­app/­modules/­points/­ServiceProvider.php5 

我还在composer.json文件中添加了自动加载输入.

i also add autoload entery in composer.json file like.

"autoload": {
  "classmap": [
    "app/modules"
   ]
 },

然后也运行这个命令.

composer dump-autoload

但是之后是行不通的.

我还在 app.php 中注册了我的 ServiceProvide.

i also register my ServiceProvide in app.php like.

'providers' => array(
       'AppModulesPointsServiceProvider'
 ),

请告诉我哪里做错了.

谢谢.

推荐答案

我尝试运行你的代码,一切正常.

I try run your code, and everything works great.

这是 Laravel 4.1 的全新安装

It's a new installation of Laravel 4.1

Obs.:检查您的 vendor/composer/autoload_classmap.php

<?php

// autoload_classmap.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    'App\Modules\Points\ServiceProvider' => $baseDir . '/app/modules/points/ServiceProvider.php',
    'App\Modules\ServiceProvider' => $baseDir . '/app/modules/ServiceProvider.php',
    'BaseController' => $baseDir . '/app/controllers/BaseController.php',
    'DatabaseSeeder' => $baseDir . '/app/database/seeds/DatabaseSeeder.php',
    'HomeController' => $baseDir . '/app/controllers/HomeController.php',
    'IlluminateQueueClosure' => $vendorDir . '/laravel/framework/src/Illuminate/Queue/IlluminateQueueClosure.php',
    'SessionHandlerInterface' => $vendorDir . '/symfony/http-foundation/Symfony/Component/HttpFoundation/Resources/stubs/SessionHandlerInterface.php',
    'TestCase' => $baseDir . '/app/tests/TestCase.php',
    'User' => $baseDir . '/app/models/User.php',
);

composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "laravel/framework": "4.1.*"
    },
    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
      "app/modules",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "stable"
}

app.php

<?php
'providers' => array(

  'IlluminateFoundationProvidersArtisanServiceProvider',
  'IlluminateAuthAuthServiceProvider',
  'IlluminateCacheCacheServiceProvider',
  'IlluminateSessionCommandsServiceProvider',
  'IlluminateFoundationProvidersConsoleSupportServiceProvider',
  'IlluminateRoutingControllerServiceProvider',
  'IlluminateCookieCookieServiceProvider',
  'IlluminateDatabaseDatabaseServiceProvider',
  'IlluminateEncryptionEncryptionServiceProvider',
  'IlluminateFilesystemFilesystemServiceProvider',
  'IlluminateHashingHashServiceProvider',
  'IlluminateHtmlHtmlServiceProvider',
  'IlluminateLogLogServiceProvider',
  'IlluminateMailMailServiceProvider',
  'IlluminateDatabaseMigrationServiceProvider',
  'IlluminatePaginationPaginationServiceProvider',
  'IlluminateQueueQueueServiceProvider',
  'IlluminateRedisRedisServiceProvider',
  'IlluminateRemoteRemoteServiceProvider',
  'IlluminateAuthRemindersReminderServiceProvider',
  'IlluminateDatabaseSeedServiceProvider',
  'IlluminateSessionSessionServiceProvider',
  'IlluminateTranslationTranslationServiceProvider',
  'IlluminateValidationValidationServiceProvider',
  'IlluminateViewViewServiceProvider',
  'IlluminateWorkbenchWorkbenchServiceProvider',
  'AppModulesPointsServiceProvider'
  ),

app/modules/points/ServiceProvider.php

<?php

namespace AppModulesPoints;

class ServiceProvider extends AppModulesServiceProvider {

  public function register() {
    parent::register("points");
  }

  public function boot() {
    parent::boot("points");
  }

}

app/modules/ServiceProvider.php

<?php 

namespace AppModules;

abstract class ServiceProvider extends IlluminateSupportServiceProvider {

  public function boot() {
    if ($module = $this->getModule(func_get_args())) {
      $this->package("app/" . $module, $module, app_path() . "/modules/" . $module);
    }
  }

  public function register() {

    if ($module = $this->getModule(func_get_args())) {
      $this->app["config"]->package("app/" . $module, app_path() . "/modules/" . $module . "/config");

        // Add routes
      $routes = app_path() . "/modules/" . $module . "/routes.php";
      if (file_exists($routes))
        require $routes;
    }
  }

  public function getModule($args) {
    $module = (isset($args[0]) and is_string($args[0])) ? $args[0] : null;
    return $module;
  }

}

这篇关于未找到 Laravel 类“AppModulesServiceProvider"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)