-1

我非常小心地创建了这个类,但我不确定它有什么问题。如果我没有任何内容,代码运行完美,

class TemplateOne{

}

但是一旦我运行这段代码,它就会中断,

<?php

class TemplateOne {

    //Properties
    protected $_bgColor;
    protected $_logoImagePath;
    protected $_headerText;
    protected $_leftContentHeader;
    protected $_rightContentHeader;
    protected $_leftContentBody;
    protected $_rightContentBody;
    protected $_footer;
    protected $_mediaIframe;
    protected $_mediaHeight = '';
    protected $_mediaWidth = '';

    //DB communication
    public $DB;

    //Constructor
    public function __construct(){

        //Connect database in construct and close connection in destruct

        $config = array();

        $config['host'] = 'localhost';
        $config['user'] = 'root';
        $config['pass'] = 'root';
        $config['database'] = 'fanpage_application';

        $this->DB = new DB($config);

        //init variables
        populateDataFromDataBase();
    }

    //Functions
    public function populateDataFromDataBase() {

        //Get bgcolor
        $this->DB->("SELECT backgroundimage FROM template_style_data WHERE styleid='#list_level'");
        $data = $this->DB->Get();
        foreach($data as $key => $value)
        {
            echo $value['backgroundimage'];
        }
    }

    //Getters
    public function getBgColor()
    {
        return $this->_bgColor;
    }

    public function getLogoImagePath()
    {
        return $this->_logoImagePath;
    }

    public function getHeaderText()
    {
        return $this->_headerText;
    }

    public function getLeftContentHeader()
    {
        return $this->_leftContentHeader;
    }

    public function getRightContentHeader()
    {
        return $this->_rightContentHeader;
    }

    public function getLeftContentBody()
    {
        return $this->_leftContentBody;
    }

    public function getRightContentBody()
    {
        return $this->_rightContentBody;
    }

    public function getFooter()
    {
        return $this->_footer;
    }

    public function getMediaIframe()
    {
        return $this->_mediaIframe;
    }

    //Setters

    public function setBgColor($bgColor)
    {
         $this->_bgColor = $bgColor;
    }

    public function setLogoImagePath($logoImagePath)
    {
         $this->_logoImagePath = $logoImagePath;
    }

    public function setHeaderText($headerText)
    {
         $this->_headerText = $headerText;
    }

    public function setLeftContentHeader($leftContentHeader)
    {
         $this->_leftContentHeader = $leftContentHeader;
    }

    public function setRightContentHeader($rightContentHeader)
    {
         $this->_rightContentHeader = $rightContentHeader;
    }

    public function setLeftContentBody($leftContentHeader)
    {
         $this->_leftContentBody = $leftContentHeader;
    }

    public function setRightContentBody($rightContentBody)
    {
         $this->_rightContentBody = $rightContentBody;
    }

    public function setFooter($footer)
    {
         $this->_footer = $footer;
    }

    public function setMediaIframe($mediaIframe)
    {
         $this->_mediaIframe = $mediaIframe;
    }

}

?>
4

4 回答 4

4

您缺少$this->对 的调用populateDataFromDataBase

于 2012-04-30T16:13:17.347 回答
3

这是您的错误:

$this->DB->("SELECT backgroundimage FROM template_style_data WHERE styleid='#list_level'");

这不是有效的语法,您需要在$this->DB.

于 2012-04-30T16:14:18.887 回答
3

DB 类从何而来?如果还没有include正确的类定义文件,您可能需要它。

$this->DB = new DB($config);

以下不是合法的语法。您将需要按名称实际调用函数。

$this->DB->("SELECT backgroundimage FROM template_style_data WHERE styleid='#list_level'");

除非您在全局范围内有另一个名为populateDataFromDataBase您要调用的函数,否则您需要$this->在尝试在构造函数中调用它之前添加。

populateDataFromDataBase();
于 2012-04-30T16:15:21.173 回答
1

就我而言,只有一个可能的答案:检查您的 PHP 错误http://php.net/manual/en/function.error-reporting.php

至少(仅在开发中,不要在生产中显示错误):

ini_set('display_errors', 1);
error_reporting(-1);
于 2012-04-30T16:18:46.237 回答