-1

我有编码新项目。我创建了一个新系统,因为它是如此混合。首先我有主类,它有3个变量;

  • 数据库变量:它有 ezSQL 类,名称是 $db
  • 存储类:我有帮助类,它存储了这个变量,它用 $store 命名
  • 存储数据:我已将站点选项和其他 mysql 数据命名为 $stored_data

及其代码:

class main {
  var $db;
  var $store;
  var $stored_data;

  public function main(){
    global $db; // ezsql class
    $this->db=$db;
  }

  public function get_helper_class($classname){
    if(isset($this->store[$classname]))
      return $this->store[$classname];
    include_once "helperclass/".$classname.".php";
    $this->store[$classname]=new $classname;
    return $this->store[$classname];
  }
}

和示例助手类它的名称选项

class option extends main {
  public function get_option($optname){
    if($this->stored_data['option'][$optname])
      return $this->stored_data['option'][$optname];
    // else get result and put stored_data
  }
}

如果我使用第二个助手

class example extends main{
  public function get_data($dataname){
    return $this->get_helper_class('option')->get_option('optionname');
  }
}

但是当我调用助手类时,我的助手看不到 $store['option'] 数据,它创建了新的选项类。问题:

辅助类无法从主类获取 $store、$db、$stored_data 变量。

我想获得编辑过的数据和变量,但它总是会创建新数据。我能做些什么?

4

1 回答 1

0

也许得到正确的选择?它还取决于您如何设置选项:

return $this->get_helper_class('option')->get_option($dataname);
于 2013-10-11T14:27:35.500 回答