How to register library classes globally?

132 views
Skip to first unread message

Bartsch, Rene

unread,
Feb 10, 2012, 3:52:13 AM2/10/12
to joomla-de...@googlegroups.com
Hi,

I've created a library which has a "lib" directory for PHP classes (filename = classname + .php suffix) and a XML manifest for installation (<folder>lib</folder>).

How can I make classes available site-wide?
Can I use "JLoader::discover()" to search and register all classes site-wide in the lib directory?
Can I run "JLoader::discover()" automatically in a library or do I need a additional plugin to register the classes?

Thanx for any help,

Renne

--
Sent with love from the new tine 2.0 email client ...
Please visit http://tine20.org

Sam Moffatt

unread,
Feb 20, 2012, 12:27:31 AM2/20/12
to joomla-de...@googlegroups.com
If you put your library in /libraries then you could do something like

/libraries/bartsch/filename.php

will match:

jimport('bartsch.filename');


However you are correct that to have it automatically load classes you
will need a system plugin. With recent changes in the platform you
will be able to register your own prefix to autoload classes that
match our new autoloader standard so you could in future use that as
an alternative to JLoader::discover().

Cheers,

Sam Moffatt
http://pasamio.id.au

> --
> You received this message because you are subscribed to the Google Groups
> "Joomla! General Development" group.
> To post to this group, send an email to joomla-de...@googlegroups.com.
> To unsubscribe from this group, send email to
> joomla-dev-gene...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/joomla-dev-general?hl=en-GB.

Bartsch, Rene

unread,
Feb 20, 2012, 10:03:52 AM2/20/12
to joomla-de...@googlegroups.com
I want to avoid fiddling around with paths.

Beginning with which version of Joomla the autoloader will be available?

I also tried writing a system-plugin. It works with a hardcoded directory path, but not when I try to use parameters.

plg_thm_lib_reg.xml:

    <config>
        <fields name="params">
            <fieldset name="basic">
                <field name="directory_prefix" type="text" default="lib_thm_*" label="Directory prefix (relative to Joomla library directory) (comma-separated) (wildcard = '*')" description="DESC_DIR_PREFIX"/>
            </fieldset>
        </fields>
    </config>

But when I add a "$test = $this->params->get('directory_prefix', 'TEST');" to "plg_thm_lib_reg.php", I only get a white page in Joomla! 1.7.5.
It makes no difference whether "$test = $this->params->get('directory_prefix', 'TEST');" is in  the constructor or in "onAfterInitialise()".

Are there any limitations for parameters in system-plugins?

Cheers,

Rene Bartsch

Rouven Weßling

unread,
Feb 21, 2012, 4:58:40 PM2/21/12
to joomla-de...@googlegroups.com

On 20.02.2012, at 16:03, Bartsch, Rene wrote:

Beginning with which version of Joomla the autoloader will be available?

The platform autoloader is available in Joomla 2.5. There's also an autoloader for the CMS libraries present.

The new autoloader that allows registering custom prefixes/locations is definitively gonna be present in Joomla 3.0 but it may be backported.

Rouven
Reply all
Reply to author
Forward
0 new messages