1

私は次の関数を持っていますが、これは現時点ではdefault.phpファイルにあり、後でhelper.phpに移動します。

function getauthor($shouts, $i){
    $db = JFactory::getDBO();
    $query = $db->getQuery(true);
    $query->select('*')
    ->from('#__users')
    ->where('name = '. $shouts[$i]->name);
    $db->setQuery($query);
    $rows = $db->loadObjectList();
    $i=0;
    foreach ($rows as $row){
        $author[$i]->id = $row->id;
        $author[$i]->name = $row->name;
        $i++;
    }
    return $author;
}

基本的に私がやりたいのは印刷ですが、$author[$i]->nameこれを試みるたびに次のコードを使用します。

print stripslashes($author[$i]->name);

次のエラーが発生します。

Undefined variable: author in C:\wamp\www\Joomla25\modules\mod_xxx\tmpl\default.php on line 98

Trying to get property of non-object in C:\wamp\www\Joomla25\modules\mod_xxx\tmpl\default.php on line 98

Cannot redeclare getauthor() (previously declared in C:\wamp\www\Joomla25\modules\mod_xxx\tmpl\default.php:60) in C:\wamp\www\Joomla25\modules\mod_xxx\tmpl\default.php on line 60

誰かが私がどこで間違っているのか、そしてどのように印刷するのか教えてもらえます$author[$i]->nameか?

4

1 に答える 1

1

author呼び出す場所で変数を定義する必要があります。

print stripslashes($author[$i]->name);

可能な限り最小の例:

$author = getauthor(....)
...
print stripslashes($author[$i]->name);
于 2013-01-06T17:36:47.133 に答える