简体   繁体   English

如何从包中访问全局类?

[英]How can I access global classes from within a package?

I created a package which also contains his own controller files and also a router.php file. 我创建了一个包,其中还包含他自己的控制器文件以及router.php文件。

My problem is that i can't access anyone of the main classes like Schema or View . 我的问题是我无法访问任何主要类,例如SchemaView

I always get a Error: Class not Found error. 我总是收到错误:找不到类错误。

I'm assuming you're using namespaces in your package, which you should be. 我假设您在包中使用名称空间,应该使用它。 As a result, you need to precede global classes with a backslash to access them. 因此,您需要在全局类之前加反斜杠以访问它们。 For example, View::make() becomes \\View::make() . 例如, View::make()变为\\View::make()

Alternatively, you could import the Facades: 或者,您可以导入外观:

<?php
namespace Your\Namespace;

use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\View;

//...

View::make($view, $data);

See the PHP namespace FAQ . 请参阅PHP名称空间常见问题解答

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM