3

我正在尝试从 Joomla 2.5.14 中获取当前的 page_id、user_id 和日期。这是我正在使用的代码:

<?php
$foo = $jinput->get('id');
echo $foo;


$user =& JFactory::getUser();
$usr_id = $user->get('id');
echo $usr_id;

$date =& JFactory::getDate();
echo 'Current date and time is: ' . $date->toFormat() . "\n";

?>

JFactory 工作正常(我得到了当前用户和日期)但 jinput 给出了错误:

Notice: Undefined variable: jinput in`
4

1 回答 1

7

你忘了定义$jinput

<?php
$jinput = JFactory::getApplication()->input;

$foo = $jinput->get('id');
echo $foo;

$user = JFactory::getUser();
$usr_id = $user->get('id');
echo $usr_id;

$date = JFactory::getDate();
echo 'Current date and time is: ' . $date->toFormat() . "\n";

?>

在旁注中,您不需要使用&.

希望这可以帮助

于 2013-08-23T10:39:49.633 回答