当我在A类做一个查询,我把所有的数据了。 B类需要使用一些数据。我更喜欢查询结果的通部分到B比做B. B类新的查询将执行一些工作,数据将在B类改变如何传递给B类数组$ something_else?这里是类:通查询产生的另一个类
class A{
public $something;
private $_project_obj;
function __construct($id = null){
if ($id) {
$this->id = $id;
$this->populate($this->id);
}
}
function populate(){
$query = //do query
$this->somthing= $query['A'];
$this->something_else = $query['B'];
}
function save(){
// call save() in class B, $something_else is saved there
if ($this->_project_obj instanceof B) {
if (true !== $this->_project_obj->save()) {
return false;
}
}
// save $something and other stuffs in class A
// ......
}
function project() {
if (!$this->_project_obj instanceof B) {
if (($this->id) && (loggedin_user_id())) {
$this->_project_obj = new B($this->id, loggedin_user_id());
} else {
return false;
}
}
return $this->_project_obj
}
}
class B{
public $data_this;
public $data_that;
function __constructor($id=null, $user_id=null){
if($id && $user_id){
return $this->populate();
}
return true;
}
function populate(){
$query = // do the same query as in class A
$something_else = $query['B'];
$this->data_this = $something_else['a'];
$this->data_that = $something_else['b'];
}
function save(){
// save all data as $something_else
}
function jobs(){
// perform jobs
}
}
“如何传递数组$ something_else”...什么?目前还不清楚这里需要发生什么。 – MidnightLightning
至B类。除B类需要数据外,其余需要发生。 – Jenny