0

所以我一直在做一些 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';
    }
}

--> 索引.php

require('front/config.php');
require('front/bootstrap.php');

 $site = new bootstrap();

完成此操作后,我尝试使用扩展通过引导类调用视图类。

我一直在尝试很多不同的事情,但我认为我已经很接近了。有谁知道如何解决这个问题?当我把它放在 bootstrap 类中时,showpage 函数确实有效,但是当我把它放在视图类中时,什么都不起作用。提前致谢!

4

0 回答 0