PDO 在我刚刚做的时候工作正常,$backend->fetchAdminInfo();
但是当我$backend->fetchAdminInfo();
在单独的函数中做时,没有返回任何结果。出于某种原因,它在应该返回first_name
、last_name
和时返回 null avatar
。
这是代码。
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!");
}
}