Forums / Cotonti / Support / Global $db_pages in localhost is null?

Eugene
#1 2013-02-04 17:24

Hello.

Guys, it is not first time i mentioned problems with my localhost apache:

some global variables are null !

When I upload site to hosting - it is working well. But while it is on localhost - I need to define variables...

example: plugin which works with hook users.details.tags

what is wrong?

Trustmaster
#2 2013-02-04 17:40

Your plugin should require page module to use its functions or tables, at the top of it do:

require_once cot_incfile('page', 'module');

 

May the Source be with you!
Eugene
#3 2013-02-04 18:01

Trust, it is what I may do easily, but I don't like it.

Let me clarify: if I do

global $db, $db_pages;

On hosting - I will get normal variable, but on localhost - null.

How I can fight it?

Добавлено 1 часа спустя:

I found a reason, i guess.

during development somtimes I turn off CACHE $cfg['cache'] = FALSE;

That makes those global variable null. I don't know if that's right, but I'm glad it's solved.

This post was edited by Eugene (2013-02-04 19:10, 11 years ago)
Trustmaster
#4 2013-02-05 14:34

The cause of the problem lays in the execution order. The availability of globals/functions depends on in which order files are required and the code is executed. Enabling/disabling cache affects this flow as well.

As plugin developers we prefer to require APIs we want explicitly every time we need it, because it is better than relying on some other plugin to do it for us, which simply might not be present.

May the Source be with you!
Eugene
#5 2013-02-05 17:58

ok.

so, your guidline for pluginmaking - is to include functions of Page module each time I need to work with Pages and $db_pages...?

not to rely on that as on global variable?

Trustmaster
#6 2013-02-05 19:29

Right. The exception is when hooking to the page module itself. And of course you don't need to require the page module if your plugin has already done it in some other hook which is executed before current hook.

May the Source be with you!