dslk6326846 2016-07-14 07:44
浏览 53
已采纳

在Laravel 5.2外部应用程序上创建模块

I'm currently creating a modular laravel project here was my reference link

Creating a Modular Application in Laravel

Right now I want to create a module folder same directory with my app folder

Folder Structure

I also create a ModuleServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class ModuleServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {

        $modules = config('modules');

        if (ENVIRONMENT != 'local') {

        } else {

            foreach ($modules as $key => $module) {

                // Load the routes for each of the modules
                if(file_exists(__DIR__ . "../../../modules/{$module}/routes.php")) {
                    require __DIR__ . "../../../modules/{$module}/routes.php";
                } else {
                    echo "{$module} Module Not found"; die;
                }

                // Load the views
                if(is_dir(__DIR__ . "../../../modules/{$module}/views")) {
                    $this->loadViewsFrom(__DIR__ . "../../../modules/{$module}/views", $module);
                } else {
                    echo  "{$module} Module View Not found"; die;
                }
            }

        }

    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

I added the ModulerServiceProvider class to my

config/app.php

providers' => [
    App\Providers\ModuleServiceProvider::class,
]

and here is the route under modules/yinyang/route.php being added

Route::group(['prefix' => 'yinyang', 'namespace' => 'Modules\Yinyang\Controllers'], function () {

    Route::get('/', 'GameController@index');
});

Here is the modules/yinyang/controller/GameController.php

namespace Modules\Yinyang\Controllers;

use App\Http\Controllers;

class GameController extends Controller {


    public function __construct() {

    }

    public function index() {

    }

}

And Here is the problem when i am trying to access already the route under yinyang module http://192.168.200.30/try/sample/public/yinyang

Class Modules\Yinyang\Controllers\GameController does not exist

Anyone has any advice/suggestion on how to solve this problem. Thanks.

  • 写回答

1条回答 默认 最新

  • dongqiong8021 2016-07-14 08:20
    关注

    I solve the problem with the help of

    Modular Structure Laravel 5

    For me to access the module directory I need to add new instance on my composer.json Modules to the psr-4

    "psr-4": {
        "App\\": "app/",
        "Modules\\": "modules/"
    }
    

    After that run composer dump-autoload to create a new build.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题