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:
- Install Jumi.
- Go to dashboard (Admin panel).
- Click on Components -> New.
- Enter title.
- In custom script, you can put your PHP/JavaScript code directly or
- 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.
精彩评论