Class phalcon类中命名空间与use语句冲突
我对index.php中注册的名称空间和实现相关名称空间的类之间的冲突感到非常困惑。 在index.php中:Class phalcon类中命名空间与use语句冲突,class,namespaces,Class,Namespaces,我对index.php中注册的名称空间和实现相关名称空间的类之间的冲突感到非常困惑。 在index.php中: $loader->registerNamespaces( array( 'Akademik\Controllers' => __DIR__ . $config->application->controllersDir, 'Akademik\Plugins' => __DIR__ . $config->appli
$loader->registerNamespaces(
array(
'Akademik\Controllers' => __DIR__ . $config->application->controllersDir,
'Akademik\Plugins' => __DIR__ . $config->application->pluginsDir,
'Akademik\Library' => __DIR__ . $config->application->libraryDir,
'Akademik\Models' => __DIR__ . $config->application->modelsDir,
))->register();
在我的班上:
namespace Akademik\Plugins;
use Phalcon\Mvc\User\Plugin;
use Phalcon\Events\Event;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Acl;
class Security extends Plugin
{
public function __construct($dependencyInjector)
{
$this->_dependencyInjector = $dependencyInjector;
}
public function getAcl()
{
if (!isset($this->persistent->acl)) {
$acl = new Phalcon\Acl\Adapter\Memory();
当我启动index.php时,我得到:
Fatal error: Class 'Akademik\Plugins\Phalcon\Acl\Adapter\Memory' not found in C:\nginx\html\app\plugins\Security.php on line 27
我对phalcon非常陌生,也不熟悉名称空间,任何帮助都将不胜感激。Tks您没有正确的名称空间转义,并且适配器没有设置在
use
语句下,这就是为什么它被放置在Akademik\Plugins\
名称空间下面的原因
这里有两种解决方法
最简单的选择
因此,您必须将其更改为此,以添加到全局命名空间:
// Add an Escape "\" before Phalcon
$acl = new \Phalcon\Acl\Adapter\Memory();
其他选择
否则,您可以在顶部执行这样的use语句:
// Add this to the top (Alias is optional, otherwise it's new Memory())
use Phalcon\Acl\Adapter\Memory as AclMemory;
...
// Create the instance this way
$acl = new AclMemory();
希望这有帮助。您没有正确的命名空间转义,并且适配器没有设置在
use
语句下,这就是为什么它被放置在Akademik\Plugins\
命名空间下的原因
这里有两种解决方法
最简单的选择
因此,您必须将其更改为此,以添加到全局命名空间:
// Add an Escape "\" before Phalcon
$acl = new \Phalcon\Acl\Adapter\Memory();
其他选择
否则,您可以在顶部执行这样的use语句:
// Add this to the top (Alias is optional, otherwise it's new Memory())
use Phalcon\Acl\Adapter\Memory as AclMemory;
...
// Create the instance this way
$acl = new AclMemory();
希望有帮助