未加载Mustache_Engine,由于设置命名空间而发生冲突? [英] Mustache_Engine not loading, conflict due to setting namespace?

查看:112
本文介绍了未加载Mustache_Engine,由于设置命名空间而发生冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码是我试图将Moustache加载到Composer库中(这意味着库本身也将由整个项目的composer加载).

The code below is me attempting to load Mustache into a Composer library (meaning the library itself is also being loaded by composer by the full project) I'm making for a project.

<?php

namespace TradeDefender\SiteEngine;

require '../../vendor/autoload.php';

class MessageEngine{

  function test(){
    $m = new Mustache_Engine;
    return "hello";
  }

}

?>

库本身的目录结构如下:

The directory structure for the library itself looks like this:

.
├── lib
│   └── TradeDefender
│       ├── Api
│       ├── Conn
│       └── SiteEngine
└── vendor
    ├── composer
    └── mustache

我怀疑这是由于我在类中设置了名称空间,但是我不确定如何解决它.错误本身是因为它无法在SiteEngine文件夹中找到Class Mustache_Engine.自动加载器本身正在加载中.

I'm suspecting that it's due to me setting a namespace in the class, but I'm not sure how to fix it. The error itself is that it's not able to find the Class Mustache_Engine in the SiteEngine folder. The autoloader itself is being loaded just fine.

有什么想法吗?谢谢.

推荐答案

问题是我从本地定义的名称空间而不是全局名称空间加载Mustache_Engine.要从全局名称空间加载,我必须在Mustache_Engine前面加一个\,例如:

The problem was that I was loading the Mustache_Engine from the locally defined namespace rather than the global namespace. To load from the global namespace I had to put a \ infront of Mustache_Engine, like so:

$m = new \Mustache_Engine;

这篇关于未加载Mustache_Engine,由于设置命名空间而发生冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆