0

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.

jrgilman
  • 460
  • 1
  • 4
  • 15

1 Answers1

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;
jrgilman
  • 460
  • 1
  • 4
  • 15