2015-11-05 65 views
-1

这是用户类。如何解决致命错误 - 在php中找不到类'User'

<?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.phpadmin->includes->user.php里面给出了错误。

回答

2

您需要在viewuser.php脚本中包含该用户类!

include_once("includes/user.php"); 

我不确定如何组织您的文件夹,这是最好的办法,但它应该工作。

+0

将namespacing作为更好的形式值得一提。 – Shawn

相关问题