我试图将“user_app”表中的数据检索到视图页面中的表格中。
这是我的控制器(方法):
public function getUserApps($email) {
$userAppsModel = new UserApps($this->pdo);
$apps = $userAppsModel->get($email);
return $this->view('user/dashboard', ['apps' => $apps]);
}
这里是我用来获取数据的方法:
public function get($email) {
$sql = "SELECT * FROM $this->table WHERE email = :email";
$stmt = $this->pdo->prepare($sql);
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->execute();
$user = $stmt->fetch(PDO::FETCH_ASSOC);
return $user;
}
这是我的查看页面 (dashboard.php) 第 107 行:
<h1>User List</h1>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Role</th>
</tr>
**Line 107:** <?php foreach ((array) $apps as $app) : ?>
<tr>
<td><?= $app['app_name'] ?></td>
<td><?= $app['app_desc'] ?></td>
<td><?= $app['app_cat'] ?></td>
</tr>
<?php endforeach; ?>
</table>
获取错误: 警告 : 未定义的变量 $apps 在 C:\xampp\htdocs\xxxxxx view\user\dashboard.php 在线的 107