我喜欢3个共享控制器。 SharedAdsController,SharedUserController和SharedCategoriesAndPropertiesController。
如果我想在彼此之间使用它们,我会获得允许的内存大小。更改内存限制不是选项。
SharedUserController:
class clsSharedUserController{
// controller
protected $o_clsSharedAdsController;
protected $o_clsSharedCategoriesAndPropertiesController;
// construct
public function __construct($smarty, $db) {
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
if (is_object($db)) {
$this->db = $db;
} else {
throw new Exception("db not set!");
}
// controller
$this->o_clsSharedAdsController = new clsSharedAdsController($this->o_smarty, $this->db);
$this->o_clsSharedCategoriesAndPropertiesController = new clsSharedCategoriesAndPropertiesController($this->o_smarty, $this->db);
}
}
SharedAdsController:
class clsSharedAdsController{
// controller
protected $o_clsSharedUserController;
protected $o_clsSharedCategoriesAndPropertiesController;
// construct
public function __construct($smarty, $db) {
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
if (is_object($db)) {
$this->db = $db;
} else {
throw new Exception("db not set!");
}
// controller
$this->o_clsSharedUserController = new clsSharedUserController($this->o_smarty, $this->db);
$this->o_clsSharedCategoriesAndPropertiesController = new clsSharedCategoriesAndPropertiesController($this->o_smarty, $this->db);
}
}
SharedCategoriesAndPropertiesController
class clsSharedCategoriesAndPropertiesController{
// db
protected $o_clsDBCategoriesAndProperties;
// construct
public function __construct($smarty, $db) {
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
if (is_object($db)) {
$this->db = $db;
} else {
throw new Exception("db not set!");
}
$this->o_clsDBCategoriesAndProperties = new clsDBCategoriesAndProperties($this->db);
}
正如您所看到的,sharedUsercontroller正在创建一个新的sharedadscontroller,sharedadscontroller正在创建一个新的sharedusercontroller。我认为这会变成一个循环。我怎样才能解决这个问题?我的意思是我可以简单地删除创建新控制器的行,但我需要来自其他控制器的数据。我能以某种方式检查控制器是否存在或者我应该以其他方式进行检查吗?如果是这样,怎么样?