![](/img/trans.png)
[英]TYPO3: when/how to use define('TYPO3_MODE','FE');
[英]TYPO3 how use 'use'
以上是来自https://docs.typo3.org/m/typo3/book-extbasefluid/main/en-us/7-Controllers/1-Creating-Controllers-and-Actions.html
的截图。
如您所见,在一种情况下MyVendor
之前没有“\”,而在另一种情况下是。 两种方式都可能吗?
在我的扩展中,我在Classes
下有以下结构。
如果我用use
function,就没有必要在`Classes里声明了。
use MyVendor\ExtName\Controller\MainController
就足够了吗?
use
'ing 命名空间,而不是文件结构,因此您必须use
确切的命名空间use
class。如果 function(不是方法)在命名空间下,则必须使用 function(因为没有 class 可以使用)\
是可选的,但首选样式是不带前导\
// a.php
namespace MyVendor\ExtName\Controller;
function test() {
echo 'Test2';
}
class MainController {
public static function test() {
echo 'Test';
}
}
// b.php
namespace AnotherVendor\ExtName\Controller;
class MainController {
public static function test() {
echo 'Test 3';
}
}
// c.php
namespace MyVendor\ExtName\Utilities;
use MyVendor\ExtName\Controller\MainController;
use AnotherVendor\ExtName\Controller\MainController as AnotherController;
use function MyVendor\ExtName\Controller\test;
class MainUtility {
public function foo() {
MainController::test();
AnotherController::test();
test();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.