globals not available in plugins?

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
Foden

globals not available in plugins?

Post by Foden »

Hi..

Is it not possible to use $_GET[] in plugins, in CMSMS? I have tried some different things now, and it gives me grey hairs.. :(

Regards
Thomas
Foden

Re: globals not available in plugins?

Post by Foden »

Further to the above...

I found out that I can do the following :
echo $_GET["page"]; and get the page ID.

But if I try the following :

while (list ($key, $val) = each ($_GET)) {
echo "$key => $val";
}

I don't get any output from the same page..

Also, count($_GET) returns the correct number of parameters, yet.. Still no output for the while loop.

Any clues? Or am I trying the impossible here?

Regards
Thomas
cyberman

Re: globals not available in plugins?

Post by cyberman »

Foden wrote: I found out that I can do the following :
echo $_GET["page"]; and get the page ID.
I'm not a coder for real but have you made a look at tag {get_template_vars}?

Maybe helps ...
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

Re: globals not available in plugins?

Post by Dee »

I'm not a coder for real but have you made a look at tag {get_template_vars}?
In Smarty you can access a $_GET['foo'] variable with through the smarty variable:

Code: Select all

{$smarty.get.foo}
Regards,
D
Foden

Re: globals not available in plugins?

Post by Foden »

This doesn't help.. As I have an existing application written in php, that I'm trying to include into cms. So I can not use smarty tags.

What I need is to use the php super globals like $_GET[], and this is apparently not possible. Why I don't understand? Because the documentation available on php.net, is that it $_GET is ALWAYS available, in all scopes of the php code.

And as my example from before.. I can use $_GET['page'], but I can not use the function

while (list ($key, $val) = each ($_GET)) {
echo "$key => $val";
}


Which will list all the elements in the array $_GET[]

There is something in the array, and I can't figure out why.. Any supercoders?????  ;D

/ Thomas
Foden

Re: globals not available in plugins?

Post by Foden »

Done some more testing..

my user defined tag includes the following code :
include "twg15/index.php";

index.php includes some other files, for filefunctions etc.

at some point in time in index.php I do the following :

$basedir = $install_dir . $basedir;
$cachedir = $install_dir . $cachedir;
$counterdir = $install_dir . $counterdir;
$xmldir = $install_dir . $xmldir;
echo $basedir."".$cachedir."".$counterdir."";

if (!checkCacheDirs()) { // checks if all cache dir are here and set the right umask
    return;
}

The echo outputs dir's as expected.. No problems there, then in checkCacheDirs() I have :
function checkCacheDirs($create_anyway = false)
{
    global $basedir, $cachedir, $counterdir, $xmldir, $install_dir, $store_xml_in_picfolders;
echo $basedir."".$cachedir."".$counterdir."";
}

Now the globals $basedir etc. are empty..

I have googled, I have searched the smarty.php.net site, I have searched php.net I have searched the forum, documentation etc. for cms. But I can't find any indication as to how or why it does work like this!

I would expect that SOMEWHERE there would be a note, either saying "this is not possible" or "to do this, you have to blah blah..."

But NONE! I'm about to give up on this.. Throw in the towel, but I don't like it.. As this is one of the things that make me wonder!

Please, code gurus.. :) HEEEELP :)

/ Thomas
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

Re: globals not available in plugins?

Post by Dee »

Seems to work fine overhere (on cmsmadesimple-1.0.2)...
I tried both your while (list ($key, $val) = each ($_GET)) code and the following code in a UDT, both work as expected.

Code: Select all

foreach ($_GET as $index => $value)
{
 echo "$index => $value<br />";
}
Grtz,
D
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

Re: globals not available in plugins?

Post by Dee »

And the include trick also works fine overhere...
I created a UDT (named test_tag) containing

Code: Select all

$test = 'test123';
include 'test/test.php';
Then a file 'test/test.php' in the webroot containing

Code: Select all

<?php
echo $test;
?>
Added the UDT to some new content using {test_tag} and voila... test123 on the screen.

So... no idea what's going wrong overthere, but it isn't you ;)

Regards,
D
Foden

Re: globals not available in plugins?

Post by Foden »

Hmmm.. that is extremely weird / annoying..  :-\

Just tried the following in a UDT :
echo "test";
while (list ($key, $val) = each ($_GET)) {
echo "$key => $val";

It only prints the "test" part..

I'm also using CMS 1.02 here, and PHP 5.2.0, those of you that has it working, are you using php4? Could it be a setting problem in php?

New info: Tried php 4.4.2 / Apache2 same problem, tried php 4.4.2 / apache 1.3, SAME PROBLEM.. I have tried to mess arround with REGISTER_GLOBALS etc. hmm.. still a problem..

I have seen it working on friends website, running cms.. It must be something in the setup of the server. But I can't figure out where it could be..

more new info...

I have partly success now! At least I can make an UDT that lists the $_GET[] array! Started to mess arround with the php.ini, and copied the php.ini-recomended (recomended for production server) to the php.ini used.. Then it worked (but other sites didn't) I then went through all the settings that was changed from the default setup, and found out that "magic_quotes_gpc off" did the trick! It also messes up all other sites that I host. But now it partly work..

But still included files mess up in global variables...

/ Thomas
Last edited by Foden on Sun Jan 14, 2007 7:48 pm, edited 1 time in total.
Post Reply

Return to “Developers Discussion”