这是我启动Application类的索引文件。当我运行它时我得到致命错误:无法在第4行的C:\ xampp \ htdocs \ blog_with_pdo \ project \ classes \ application.php中重新声明类应用程序
<?php
if(!class_exists('Application')) {
require_once'./classes/application.php';
$obj_app=new Application();
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="asset/front_end/css/bootstrap.min.css" />
<script src="asset/front_end/js/jquery.min.js"></script>
<script src="asset/front_end/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<?php
include 'includes/header.php';
?>
<div class="container-fluid">
<div class="row">
<div class="container">
<?php
include_once 'includes/left_sidebar.php';
?>
<div class="col-md-8"></div>
<?php
include 'includes/right_sidebar.php';
?>
</div>
</div>
</div>
<?php
include 'includes/footer.php';
?>
</div>
</body>
</html>
这是Application类
<?php
require_once 'db_connect.php';
class Application {
public $pdo;
public function __construct() {
$obj_db = new Db_connect();
$this->pdo = $obj_db->pdo;
}
public function select_all_published_category() {
try {
$query = "SELECT * FROM tbl_category WHERE publication_status='1' ";
$result = $this->pdo->query($query);
return $result;
} catch (PDOException $e) {
echo $e->getMessage();
}
}
}
这是left_sidebar.php,我想使用Application类对象。
<?php
$result=$obj_app->select_all_published_category();
?>
<div class="col-md-2" style="border-right: 1px solid #ffcc99; margin: 0; padding: 0;">
<nav class="nav-sidebar">
<ul class="nav tabs">
<li class="sidebar-brand">
<a href="#home"><span class="fa fa-home solo">বিষয়ভিত্তিক</span></a>
</li>
<?php
while ($row=$result->fetch(PDO::FETCH_ASSOC)) { ?>
<li><a href="#tab1" data-toggle="tab"><?php $row['category_name']; ?></a></li>
<?php } ?>
</ul>
</nav>
</div>