Loader & namepsace: can't create a \Phalcon\Tools namespace

Hi all,

I'm building a MVC app with 6 different modules, and I guess as many before me, I'd like to instanciate a "custom set" of shared tools & libraries I can use in my modules. I obviously don't want to load everything all the time in my bootstrap or module.php files.

!! Tools means a set of classes to help manage dates, urls, xml, ... a bunch of stuffs like this !!

So I thought I could create a \Phalcon\Tools namespace, containing a "tool-loader" class. I could register this custom loader as a service in the bootstrap and use it to load my libs when I need it. Problem is, I can't get it to work. Here is my setup.

App structure:

/apps
    /common
        /class
            tool_loader.php
        /libs
    /config
        bootstrap
    /modules
        /fe
        /be
        /api

In my boostrap:

$di->get('loader')->registernamespaces(array('\\Phalcon\\Tools' => PATH_CLASS.'/tool_loader.php'), true)->register();
$di->setShared('tools', function () use($di) 
{        
    return new \Phalcon\Tools\Loader($di);
});

In tool.loader.php

<?php
namespace \Phalcon\Tools;

class Loader
{
...

Result: * Fatal error: Class 'Phalcon\Tools\Loader' not found *

Could anyone tell me what I'm doing wrong. Thanks in advance

What do you get when you dump

PATH_CLASS.'/tool_loader.php'

Just to confirm your path is correct



12.8k
edited May '15

That's the first thing I've checked. Require(PATHCLASS.'/toolloader.php'); works just fine.



12.8k

Actually if I add my a requireonce(PATHCLASS.'/tool_loader.php'); in my boot strap, it works. It seems like the loader is not working properly in my setup...