我想在模块中划分我的应用程序。例如,将有一个“核心”模块,其中包含基本登录功能,应用程序布局/格式化(CSS等),用户管理和日记。
稍后我可以创建其他模块,如联系人管理器,可以轻松地添加或从应用程序中删除。
应用程序导航中会有一些逻辑来确定哪些模块存在,并显示/隐藏指向它们的链接。
我如何在目录结构,命名空间和任何其他需要的方面这样做?
我正在查看creolab / laravel-modules,但它声明它是Laravel 4.我仍然可以使用它与5完全相同的方式?
文档说要在每个模块目录中放置模型,控制器和视图,但是如何使用路由?理想情况下,我想让每个模块有自己的routes.php文件。如何将所有这些工作与http和资源目录中的东西?
我在想这样的东西:
但我不知道如何让它工作。
我刚刚在这里尝试教程:
没有额外的库等,只是纯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()方法工作?