Require_once 在 Laravel 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30458602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:38:13  来源:igfitidea点击:

Require_once In laravel

phplaravelrequire-once

提问by Clayman

I have a plugin for my site and I duplicate the folder structure and renamed the files, I try to load the new plugin I made in the global.php file the same way the original plugin loaded with

我的网站有一个插件,我复制了文件夹结构并重命名了文件,我尝试以与加载原始插件相同的方式加载我在 global.php 文件中创建的新插件

//load plugins
if(File::exists(public_path('plugins/releasedate/protected/start.php')))
{
File::requireOnce(public_path('plugins/releasedate/protected/start.php'));
}   

But when I'm adding the other plugin

但是当我添加其他插件时

//load plugins
if(File::exists(public_path('plugins/releasedate/protected/start.php')))
{
File::requireOnce(public_path('plugins/releasedate/protected/start.php'));
}

if(File::exists(public_path('plugins/streaming/protected/start.php')))
{
File::requireOnce(public_path('plugins/streaming/protected/start.php'));
}

It load's only the first plugin. Or can I use only one requireOnce in my script?

它加载的只是第一个插件。或者我可以在我的脚本中只使用一个 requireOnce 吗?

回答by num8er

Try:

尝试:

$plugins = array(
    public_path('plugins/releasedate/protected/start.php'),
    public_path('plugins/streaming/protected/start.php')
);

foreach($plugins AS $plugin) {
    if(!is_file($plugin)) {
        die("NO FILE: ".$plugin);
    }

    require_once($plugin);
}

回答by Clayman

I merged my files without a plugin folder and start.php file and everything seems to be fine. Thank you all

我在没有插件文件夹和 start.php 文件的情况下合并了我的文件,一切似乎都很好。谢谢你们