php新类对象没有被实例化

时间:2013-11-03 18:27:54

标签: php

我正在尝试从我的mvc控制器创建一个新的模型对象,但该页面不会生成。有什么理由不能这样做吗?当然我应该能够在现有的对象中创建一个对象吗?

很抱歉这么简单,我知道我听起来像个白痴,但我不知道如何解释我做错了什么。

class controller_landing extends controller_base
{
    public function __construct($get,$post)
    {
        parent::__construct($get,$post);

        $this->model = new model_landing;  <-----problem line here
    }
}

abstract class controller_base
{   
    //store headers
    protected $get;
    protected $post;

    //store layers
    protected $view;
    protected $model;

    protected function __construct($get,$post)
    {    
        //store the header arrays
        $this->get = $get;
        $this->post = $post;

        //preset the view layer as an array
        $this->view = array();
    }

    public function __destruct()
    {
        //extract variables from the view layer
        extract($this->view);

        //render the view to the user
        require_once('view/'.$this->get['controller'].'_view.php');
    }
}

class model_landing extends class_mysqli
{
    public function __construct
    {
        echo "landing model";   
    }
}

class class_mysqli
{
    public function __construct
    {
        echo "mysqli";
    }
}

1 个答案:

答案 0 :(得分:2)

我不知道,但我认为你缺少括号。 有

public function __construct
{
        echo "landing model";  
}

应该是

public function __construct()
{
        echo "landing model";   
}