drd99007 2014-05-05 12:43
浏览 27

如何在laravel中制作模块化系统

I am trying to create a modular system in Laravel 4.1.

I have folders like following:

app
app/controllers
app/controllers/BaseController.php
app/views/
app/modules/
app/modules/moduleName/
app/modules/moduleName/routes.php
app/modules/moduleName/controllers/
app/modules/moduleName/controllers/module.php

When I try to extend BaseController, I use namespaces and I get the following error:

 Symfony \ Component \ Debug \ Exception \ FatalErrorException
 Class 'Illuminate\Session' not found

Here is my module.php codes:

 <?php namespace App\Modules\Twitter\Controllers;

 use Illuminate\Routing\Controllers\Controller;

 class Modulename extends Controller {

 }

I have two questions.

  1. How can I call session classes in modules?
  2. I have route.php file in every module but still can't route the modules. Hence I am supposed to use laravel default routes.php file. How can I solve this problem?

Thanks anyway.

  • 写回答

1条回答 默认 最新

  • dsgrgaz321973284 2014-05-05 22:18
    关注

    Laravel libraries all exist in the global namespace, so if you're using namespaced code of any sort, you'll need to specify the libraries you're calling.

    Using the code you provided, it'd be like this:

    <?php namespace App\Modules\Twitter\Controllers;
    
     use Controller, Session;
    
     class Modulename extends Controller {
    
     }
    

    This saves you having to type out the entire namespace.

    评论

报告相同问题?

悬赏问题

  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上