当我刚刚执行$backend->fetchAdminInfo();
时,PDO工作正常,但当我在单独的函数中执行$backend->fetchAdminInfo();
时,没有返回任何结果。出于某种原因,当它返回first_name
,last_name
和avatar
时,它返回null。
以下是代码。
public $adminCount;
final public function fetchAdminInfo() {
global $zip, $db, $tpl;
$query = $db->prepare('SELECT first_name, last_name, avatar FROM zip__admins ORDER BY first_name ASC');
$query->execute();
$result = $query->fetchAll();
$id = 1;
foreach($result as $row) {
$tpl->define('admin: first_name-' . $id, $row['first_name']);
$tpl->define('admin: last_name-' . $id, $row['last_name']);
$tpl->define('admin: avatar-' . $id, $row['avatar']);
$id++;
}
$this->adminCount = $id;
}
final public function addSnippet($z) {
global $tpl;
if(isset($z) && !empty($z)) {
switch($z) {
case 'login: show-admins':
$this->fetchAdminInfo();
$admins = ' ';
for($id = 1; $this->adminCount > $id; $id++) {
$admins .= '<li data-name="{admin: first_name-'. $id .'} {admin: last_name-'. $id .'}" onclick="submitValue('. $id .')">';
$admins .= '<div class="av-overlay"></div><img src="{site: backend}/img/avatars/{admin: avatar-'. $id .'}.jpg" class="av">';
$admins .= '<span class="av-tooltip">{admin: first_name-'. $id .'} {admin: last_name-'. $id .'}</span>';
$admins .= '</li>';
}
$tpl->Define('snippet: show-admins', $admins);
$tpl->display();
break;
}
} else {
die("HELLO!");
}
}