1
jeffgr
xoops_userid issue
  • 2006/6/15 4:30

  • jeffgr

  • Quite a regular

  • Posts: 263

  • Since: 2004/2/22


Hi everyone,

I'm trying to modify some code, and am stuck on the following issue...


My template code is listed below in the "full description of the issue." It uses

echo "<br>" . "{$xoops_uname}";

in php code. For some reason, that's not being translated.

Isn't that one of the Smarty Variables that are supposed to be available in all modules?

I tried including header.php, but that broke the code altogether, giving an error about a call to a nonmember function. I also tried using $xoopsUser->getVar('uid'), but that gave the same error.

Here's the info:


XOOPS Version: 2.0.13.2
Module Name/Version: Tiny D0 2.22
PHP Version: 4.4.2
MySQL Version: 4.1.14
Web Server Software (Apache/IIS/Other): Apache
Operating System: XOOPS on Windows, MySQL on Debian
Theme you are using: filthy_blue
Custom template: (Yes/No) Yes
PHP Debug Messages:
Here's the offending line in the php debugger:

Notice [PHP]: Only variable references should be returned by reference in file kernel/object.php line 289
=> Notice [PHP]: Undefined variable: xoops_uname in file class/xoopsblock.php(146) : eval()'d code line 2
Notice [PHP]: Only variable references should be returned by reference in file class/xoopsblock.php line 149

MySQL Debug Messages:
Not relevant

Smarty Debug Messages: (Relevant ones)
{$xoops_uname} Group1
{$xoops_userid} 4

A full description of the issue:

Here's my template code:

echo "hello";
echo "<br>" . "{$xoops_uname}";
echo "<br>" . "{X_SITEURL}";
echo "<br>goodbye";

The SITEURL shows up on the page, the xoops_userid does not.

The PHP debug specifically says xoops_uname is not defined. However, the Smarty debug window shows the variables and their values just fine!

Isn't the xoops_uname defined in all modules/templates?

Any help will be most appreciated!

Thanks,
Jeff

2
xuser
Re: xoops_userid issue
  • 2006/6/15 5:48

  • xuser

  • Just popping in

  • Posts: 73

  • Since: 2002/11/26


xoops redefines the smarty delimiter tag to "<{}>", not original "{}"
Xuser's site
http://xuser.org
http://theme.xoops.org.cn

3
YosiG
Re: xoops_userid issue
  • 2006/6/15 12:21

  • YosiG

  • Just popping in

  • Posts: 3

  • Since: 2006/6/14


Quote:

xuser wrote:
xoops redefines the smarty delimiter tag to "<{}>", not original "{}"


Thanks, but that didn't help. That simply resulted in "<>", and between those two brackets was still empty space.

And the php debug still shows undefined variable $xoops_userid.

Thanks,
Yosi (working with Jeff)

4
Quest
Re: xoops_userid issue
  • 2006/6/15 12:48

  • Quest

  • Friend of XOOPS

  • Posts: 1034

  • Since: 2005/11/19


Try it without the echo command and the " "s: ie;

<br><{$xoops_uname}><br>

Quest

5
zyspec
Re: xoops_userid issue
  • 2006/6/15 15:32

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


If you're using it inside a template (/templates/something.html) and your template is defined in the PHP code that's calling the template then you don't need any of the echo or " ". <($xoops_user}> should be directly in the html file since it is a Smarty variable. It is available inside of a Smarty template only.

If you're not using templates (writing directly from PHP - which is what I suspect since the echo code below appears to be from a .php file) you can't use the Smarty variable. You'll need to get the user name from the database using something like this...

$usrid = XoopsUser::uid
$uname = XoopsUser::getUnameFromId($usrid);

then you can echo it like:

echo "<br />".$uname;

6
YosiG
Re: xoops_userid issue
  • 2006/6/15 23:02

  • YosiG

  • Just popping in

  • Posts: 3

  • Since: 2006/6/14


You're right. I'm not writing html, I'm writing php code to pull info from a database to create the html. The php code needs the XOOPS userid to get the correct database information.

The code you provided looks like Perl, and it certainly didn't work in my XOOPS php.

I tried this, however:

$xoopsUser->getVar('uid')

but that failed with "Call to a member function on a non-object."

Then I tried to include header.php, but that include failed with the same message, this time in header.php.

How can I get my xoops_userid in PHP?

Thanks very much,
Yosi

7
YosiG
Re: xoops_userid issue
  • 2006/6/16 1:23

  • YosiG

  • Just popping in

  • Posts: 3

  • Since: 2006/6/14


Ok - I got it.

I added: global $xoopsUser;
to the top of the code, then used: $xoopsUser->getVar('uid')
to get the userid.

Is using global variables safe?

Thanks all for your help!

8
Quest
Re: xoops_userid issue
  • 2006/6/16 1:56

  • Quest

  • Friend of XOOPS

  • Posts: 1034

  • Since: 2005/11/19


Here is a thread you may be interested in which was on the same issue.

https://xoops.org/modules/newbb/viewtopic.php?viewmode=flat&topic_id=50530&forum=27

Login

Who's Online

164 user(s) are online (82 user(s) are browsing Support Forums)


Members: 0


Guests: 164


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits