dongmeng1402 2018-04-19 14:52
浏览 81
已采纳

使用命名空间并在php / laravel中使用?

I have two files in the same directory Graph:

IModel.php

DataModel.php

For these files in the top I set namespace as: namespace App\Library\Graph;

When I try to use IModel.php in DataModel.php I do:

namespace App\Library\Graph;

use IModel;

I get response: Interface 'IModel' not found

  • 写回答

1条回答 默认 最新

  • doudeng1870 2018-04-19 14:59
    关注

    You need to include the php file and then you will be able to call the class.

    require('App\Library\Graph\IModel.php');
    
    $myClass = new IModel();
    

    You can also use an autoloader.. Then include the autoloader and all your classes that are mapped through the autoloader will be able to be called.

    Here is a link to read about autoloading using composer.

    https://phpenthusiast.com/blog/how-to-autoload-with-composer

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部