开发者

Jumi (Joomla plugin) breaking PHP global keyword

开发者 https://www.devze.com 2022-12-22 03:54 出处:网络
When I include a PHP script via Jumi, it seems to break the global keyword.Example: <?php $a = 5; function foo()

When I include a PHP script via Jumi, it seems to break the global keyword. Example:

<?php

$a = 5;

function foo()
{
        global $a;
        if (isset($a))
                echo $a;
        else
                echo '$a is not set';
}

foo();

?>

When I run this PHP scri开发者_Python百科pt (named test.php) by itself, it correctly prints 5. When I run it included via Jumi in a Joomla article solely containing this:

{jumi test.php}{/jumi}

It prints $a is not set.

Is this a bug in Jumi or Joomla, or is there some (un)documented way I'm supposed to work around it?

When I include a PHP script via Jumi, it seems to break the global keyword. Example:

<?php

$a = 5;

function foo()
{
        global $a;
        if (isset($a))
                echo $a;
        else
                echo '$a is not set';
}

foo();

?>

When I run this PHP script (named test.php) by itself, it correctly prints 5. When I run it included via Jumi in a Joomla article solely containing this:

{jumi test.php}{/jumi}

It prints $a is not set.

Is this a bug in Jumi or Joomla, or is there some (un)documented way I'm supposed to work around it?


UPDATE: If I mark $a as global in the top scope of the script:

<?php

global $a;
$a = 5;
function foo()
{
        global $a;
        if (isset($a))
                echo $a;
        else
                echo '$a is not set';
}
foo();

?>

test.php works properly both run by itself and included via Jumi. My best guess is that Jumi scripts are included in function context, not global context.


You may try a little different approach like this, as I believe Joomla limits scope by default


Working with Jumi is very easy in joomla as it is supported in 2.5, 3.0 versions
I have a solution:

  1. Install Jumi.
  2. Go to dashboard (Admin panel).
  3. Click on Components -> New.
  4. Enter title.
  5. In custom script, you can put your PHP/JavaScript code directly or
  6. You can put a filename there using Jumi syntax: {jumi[directory/filename.php]}

But remember to create menu for it so that it can appear on onclick event of menu.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号