如何修复致命错误-在php中找不到类“User”
这是用户类如何修复致命错误-在php中找不到类“User”,php,Php,这是用户类 <?php class User { /* *public static function get_all_users() */ public function get_all_users() { global $link; $result_set = $link->query("SELECT * FROM `user`"); return $result_set; } } 上
<?php
class User {
/*
*public static function get_all_users()
*/
public function get_all_users() {
global $link;
$result_set = $link->query("SELECT * FROM `user`");
return $result_set;
}
}
上面的类是我创建的用户类对象,但无法访问。显示html的所有使用页面:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Cp1252">
<title>Admin Panel ::: </title>
</head>
<body>
<h3>Users :</h3>
<table border="1">
<tr>
<th>S.N</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
<th>Password</th>
<th>E-mail</th>
<th>Contact</th>
<th colspan="2">Option</th>
</tr>
<?php
$user = new User();
$result_set = $user->get_all_users();
/*
*$result_set = User :: get_all_users(); - accessing user class using static keyword.
*/
$i = 1;
while ($row = mysqli_fetch_assoc($result_set)) {
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['first_name']; ?></td>
<td><?php echo $row['last_name']; ?></td>
<td><?php echo $row['username']; ?></td>
<td><?php echo $row['password']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['Contact']; ?></td>
<td><a href="">Update</a></td>
<td><a href="">Delete</a></td>
</tr>
<?php
$i++;
}
?>
</table>
</body>
</html>
当我创建用户类的对象时,我无法访问用户类,用户类在包含文件夹中,而下面的HTML文件在管理文件夹或admin->viewuser.php和admin->includes->user.php中,这会产生错误。您需要将该用户类包含在viewuser.php脚本中
include_once("includes/user.php");
我不确定这样组织文件夹是否是最好的方法,但它应该会起作用。提到名称空间作为更好的形式可能是值得的。