I have a some class, it include Smarty, but my class use namespace test, Smarty don't use namespaces. How include Smarty, without writing namespaces into smarty files (it has many system plugins)
我有一个类,它包括Smarty,但我的类使用命名空间测试,Smarty不使用命名空间。如何包括Smarty,而无需将命名空间写入智能文件(它有许多系统插件)
import "smarty/Smarty.php"
class testik
{
public function __construct ()
{
$smarty = new Smarty();
}
}
<?php
class Smarty
{
//somcode
}
Smarty has autoloader class and include its plugins, plugins haven't namespaces too.
Smarty有自动加载器类并包含其插件,插件也没有名称空间。
1 个解决方案
#1
34
Tell your namespaced code it's in the global namespace:
告诉您在全局命名空间中的命名空间代码:
$smarty = new \Smarty();
Additionally importingDocs works this way:
此外,importsDocs以这种方式工作:
use Smarty;
Then you can use your code as it was:
然后你可以使用你的代码:
$smarty = new Smarty();
See as well: How to use “root” namespace of php?.
另见:如何使用php的“root”命名空间?
#1
34
Tell your namespaced code it's in the global namespace:
告诉您在全局命名空间中的命名空间代码:
$smarty = new \Smarty();
Additionally importingDocs works this way:
此外,importsDocs以这种方式工作:
use Smarty;
Then you can use your code as it was:
然后你可以使用你的代码:
$smarty = new Smarty();
See as well: How to use “root” namespace of php?.
另见:如何使用php的“root”命名空间?