Mustache_Engine not loading, conflict due to setting namespace?

混江龙づ霸主 提交于 2019-12-11 16:29:14

问题


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

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.

Any ideas? Thanks.


回答1:


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;


来源:https://stackoverflow.com/questions/32160979/mustache-engine-not-loading-conflict-due-to-setting-namespace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!