Question

$loader = new \Phalcon\Loader();
$loader->registerNamespaces(
array(
   "Sabberworm"         => "app/core/Sabberworm/",
   "Parsedown"         => "app/core/Parsedown/",
))->register();

Now if i initialize Parsedown() class with

$parser = new Parsedown\Parsedown();

I'm getting:

   Fatal error: Class 'Parsedown\Parsedown' not found 

But Sabberworm works fine:

$loader = new Sabberworm\CSS\Parser();

My folder structure:

/app/
/app/core/
/app/core/Sabberworm/CSS/Parser.php
/app/core/Parser/Parsedown.php

Why Parsedown doesn't work with Universal loader?

If i use something like this:

spl_autoload_register(function($class){
require preg_replace('{\\\\|_(?!.*\\\\)}', DIRECTORY_SEPARATOR, ltrim($class, '\\')).'.php';
});

It works. But i want to use universal loader.

Was it helpful?

Solution

Try this:

$loader = new \Phalcon\Loader();
$loader->registerNamespaces(
array(
 "Sabberworm"         => "app/core/Sabberworm/",
 "Parsedown"         => "app/core/Parser/", //Now is right
))->register();

$parser = new Parser\Parsedown(); //now it works
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top