好的,所以我試圖在Controller,Model和View之上創建一個Call
類。但是,當我將該類設置爲Call
類中的數組時,它似乎將數組堆疊在一起(按調用的順序),而不是逐個放置它們。PHP數組堆棧調用類?
這裏就是我的意思是:
array(1) {
["Controller"]=>
object(Controller)#2 (1) {
["classes"]=>
array(1) {
["Controller_Pages"]=>
object(Controller_Pages)#3 (1) {
["classes"]=>
array(1) {
["View"]=>
object(View)#4 (2) {
["params"]=>
array(2) {
["Testing"]=>
string(7) "a test."
["lolni"]=>
string(7) "a test."
}
["classes"]=>
array(0) {
}
}
}
}
}
}
}
看來在,我打電話給他們的順序來堆放它們。
這裏的呼叫類:
<?php
class Call {
public $classes = Array();
public function __call($name, $args) {
if(!is_object($this->classes[$name])) {
require_once 'Slave/' . str_replace('_', '/', $name) . '.php';
$this->classes[$name] = new $name();
// to confirm that they are being stacked in the order they are being called
echo $name . "\n\n";
}
return $this->classes[$name];
}
public function dump() {
var_dump($this->classes);
}
}
因此控制器內部,例如,你會打電話像這樣一類:
<?php
// Class -> Function
$this->Model()->query();
這裏的來源,如果你想看看:
http://joshfoskett.com/View/Call_Issue
因此問題是,我將如何獲得數組看起來像這樣?
array(3) {
["Controller"]=>
object(Controller)#1 (1) {
["classes"]=>
array(0) {
}
}
[0]=>
object(Controller_Pages)#2 (1) {
["classes"]=>
array(0) {
}
}
["View"]=>
object(View)#3 (2) {
["params"]=>
NULL
["classes"]=>
array(0) {
}
}
}