所以我一直在做一些OOP而且遇到了麻烦。我正在尝试在另一个PHP文件中扩展一个类。扩展类应该动态加载。我把它设置成这样:
bootstrap.php 档案:
<?php
class bootstrap{
public $lang;
public $page;
public $action;
public $id;
public $message;
public function __construct() {
$this->buildPage();
}
public function buildPage() {
if($this->page == 'home'){
require_once CONTR . 'view.php';
new view($this->lang, $this->page, $this->action, $this->id, $this->message);
}
}
}
和 view.php 文件:
class view extends bootstrap{
public $lang;
public $page;
public $action;
public $id;
public $message;
public function __construct($lang, $page, $action, $id, $message) {
parent::__construct();
$this->lang = $lang;
$this->page = $page;
$this->action = $action;
$this->id = $id;
$this->message = $message;
$this->showPage();
}
public function showPage() {
require_once VIEW . 'header.php';
//echo VIEW . 'header.php';
//prepare SQL statements
$page = $this->page;
$name = "name_" . $this->lang;
//SQL statement
$selectdata = mysql_query("SELECT * FROM pages WHERE $name = '$page'");
$result = mysql_fetch_array($selectdata);
//Echo content
if($result["content_$this->lang"] == NULL){
echo "no content";
} else {
echo $result["content_$this->lang"];
}
//Debugging
echo '<br>' . $this->lang;
echo '<br>' . $this->page;
echo '<br>' . $name;
echo '<br>' . $page;
require_once VIEW . 'footer.php';
}
}
- &GT;的index.php
require('front/config.php');
require('front/bootstrap.php');
$site = new bootstrap();
执行此操作后,我尝试使用extends。
通过引导类调用视图类我一直在尝试很多不同的事情,但我认为我非常接近。有谁知道如何解决这个问题? 当我把它放在bootstrap类中时,showpage函数确实有效,但是当我把它放在视图类中时,没有任何效果。 提前谢谢!