dqbh8054 2016-12-23 15:18
浏览 330
已采纳

Laravel使用外部类

I'm new on laravel and need some help. Actualy i use 5.3 laravel version. I need to use, in laravel, external company framework (call it F for semplicity). This framework is some like process manager. Actualy, for integrate it with laravel i put it in laravel/public folder, this way i can use laravel and F's pages in same domain. In laravel i need to access to some F functionality wich is all collect in class FFramework\Facade\FInterface; Then i want to acces to this class from laravel controller FController. But when i run code i get Class Not Found Exception.

This is folder structure:

  • laravel
    • app
      • http
        • controllers
        • FController.php
  • public
    • css
    • js
    • index.php
    • fframework
      • facade
        • FInterface.php
      • index.php

This is code example:

FController.php

<?php
  namespace App\Http\Controllers;

  use FFramework\facade\FInterface;

  class FController extends Controller {

      public function getSimpleDAta() {
          $f = new FInterface();
          return $f->getSimpleData();
    }
  }

FInterface.php

<?php
  namespace FFramework\facade;

  use some\internal\function;

  class FInterface {

      public function getSimpleDAta() {
          $simpleData = ...omg so much computation :) ...
          return $simpleData;
    }
  }

Exception that i get:

Class 'FFramework\facade\FInterface' not found

Additional Information

I use standard LAMP configuration PHP version is last 5.6 stable version

Question

How can i use FInterface from Laravel controller leaving FFramework in public folder?

  • 写回答

1条回答 默认 最新

  • dongtuoleng8624 2016-12-23 15:40
    关注

    You need to update the autoload section of your composer.json file to tell your project where to look for files in the FFramework namespace.

    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
            "FFramework\\": "public/fframework"
        }
    },
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?