最近开始使用UserFrosting作为项目的一部分,我在使用UserFrosting中的外观时遇到了一些问题,如果可能的话,我希望得到一些帮助。
我试图在File控制器中使用UserFrosting外观来使用以下代码在本地文件系统上创建一个文件夹
use Illuminate\Support\Facades\File; ...... $directoryCreated = File::makeDirectory($directoryPath);
但是,在运行时,我会得到以下错误
PHP Fatal error: Call to a member function makeDirectory() on null in /var/www/test-app/userfrosting/vendor/illuminate/support/Facades/Facade.php on line 210
看起来,UserFrosting应用程序不承认文件外观(或任何其他facacde -我也尝试过存储),它还没有注册到应用程序。
可以在UserFrosting中使用facade类吗?
如果是这样的话,我必须在UserFrosting应用程序配置的某个地方注册它们吗?
任何方向指针都将不胜感激。
提前感谢!
发布于 2016-10-01 19:56:06
来自正面文件
Laravel "facades“充当服务容器中底层类的”静态代理“。
因此,看起来拉拉维尔的外观依赖于拉拉维尔的服务容器。您可以在这里更多地了解Laravel如何设置默认外观:https://www.sitepoint.com/how-laravel-facades-work-and-how-to-use-them-elsewhere/#how-laravel-aliases-the-facades
不幸的是,UserFrosting没有使用Laravel的服务容器。相反,它使用纤细,它有自己的服务容器。在Slim v2 (UF0.3.1使用的)中,Slim应用程序本身就是服务容器。
您可以在initialize.php中为UF定义服务。所以,你可以尝试这样的方法:
$app->filesystem = new \Illuminate\Filesystem\Filesystem();
然后,您可以使用文件系统服务如下:
$app->filesystem->makeDirectory($directoryPath);
发布于 2016-10-01 22:01:41
您可以尝试使用Slim的容器来允许Facade解析其访问器(它将使用容器上的数组访问来解析它)。您必须确保facade使用的绑定是存在的。您可以查看与您希望使用的服务对应的服务提供程序,以了解其如何设置绑定。
File外观正在访问绑定‘文件’(Illuminate\Filesystem\Filesystem)。
\Illuminate\Support\Facades\Facade::setFacadeApplication($container);
\Illuminate\Support\Facades\File::makeDirectory(...);值得一试,但最重要的是正在解决的绑定问题。
https://stackoverflow.com/questions/39810243
复制相似问题