0

It is possible to create library package with namespace as below?

namespace Main{
  class PrefixFolderLib1{
    //functions
  }
}

Not sure how the JLoader will understand the namespace.

5

Sure. For example, create mylib folder in /library, and a file Myclass.php with the following content:

namespace mylib;

class Myclass
{
}

You can register your namespace with

JLoader::registerNamespace('mylib', JPATH_ROOT . '/libraries');

And access your class with \mylib\Myclass. Personally, I create a system plugin to do it automatically:

public function onAfterInitialise()
{  
   JLoader::registerNamespace('mylib', JPATH_ROOT . '/libraries');
}
| improve this answer | |
  • Thanks. I too initialize using system plugin only. In case if I use multiple namespaces then should I register all the name spaces onAfterInitialise? – Malaiselvan Nov 17 '15 at 16:25
  • Yup, you can do it in the same method – Marko D Nov 17 '15 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.