php 模块化,php-如何在Laravel 5中构建模块化应用程序?

我想将我的应用程序划分为模块。 例如,将有一个“核心”模块,其中包含基本的登录功能,应用程序布局/格式(CSS等),用户管理和日记。

稍后,我可以创建其他模块,例如联系人管理器,可以轻松地从应用程序中添加或删除它们。

应用程序导航中将存在一些逻辑,用于确定存在哪些模块并显示/隐藏到它们的链接。

我该如何在目录结构,名称空间和其他所需的方面做到这一点?

我正在查看creolab / laravel-modules,但它指出它适用于Laravel4。我是否仍可以以完全相同的方式将它与5一起使用?

该文档说要在每个模块目录中放置模型,控制器和视图,但是这如何与路径一起使用? 理想情况下,我希望每个模块都具有自己的route.php文件。 所有这些如何与loadViewsFrom()和resources目录中的内容一起使用?

我在想这样的事情:

f577e8f2552a37fe01a926d276299451.png

但是我不知道该如何工作。

我刚刚在这里尝试了本教程:

[http://creolab.hr/2013/05/modules-in-laravel-4/]

没有额外的库等,只有纯Laravel 5。

我似乎碰到了一条错误消息:

FatalErrorException in ServiceProvider.php line 16:

Call to undefined method Illuminate\Config\Repository::package()

关于以下内容:

abstract class ServiceProvider extends \Illuminate\Support\ServiceProvider

{

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;

}

}

是什么原因造成的,我该如何解决?

现在我对此有了更多的了解。 得到了我的包/模块路线和视图,这很棒:

abstract class ServiceProvider extends \Illuminate\Support\ServiceProvider

{

public function boot()

{

if ($module = $this->getModule(func_get_args())) {

include __DIR__.'/'.$module.'/routes.php';

}

$this->loadViewsFrom(__DIR__.'/'.$module.'/Views', 'core');

}

public function register()

{

if ($module = $this->getModule(func_get_args())) {

}

}

public function getModule($args)

{

$module = (isset($args[0]) and is_string($args[0])) ? $args[0] : null;

return $module;

}

}

我还有最后一个问题,我该如何从包装中加载所有控制器,就像loadViewsFrom()方法的工作方式一样?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值