Php 以正确的方式设置控制器类
我会尽可能用最好的方式来解释我自己。我试图从PHP中的OOP开始。我是这样开始的,我制作了一个“主控制器”,并在其中启动了所有其他控制器。我这样做是因为我希望通过控制器共享数据Php 以正确的方式设置控制器类,php,class,oop,pdo,controllers,Php,Class,Oop,Pdo,Controllers,我会尽可能用最好的方式来解释我自己。我试图从PHP中的OOP开始。我是这样开始的,我制作了一个“主控制器”,并在其中启动了所有其他控制器。我这样做是因为我希望通过控制器共享数据 class clsController{ public function __construct($smarty){ if (is_object($smarty)) { $this->o_smarty = $smarty;
class clsController{
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
$this->o_clsSharedAdsController = new clsSharedAdsController($this->o_smarty);
$this->o_clsSharedUserController = new clsSharedUserController($this->o_smarty);
}
}
在我看来,到目前为止它看起来还不错。现在的问题是,当我在类clsSharedUserController中时,它如下所示:
class clsSharedUserController extends clsController{
// construct
public function __construct($smarty) {
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
}
我无法访问CLSSharedsController中的函数。控制器看起来像这样
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
}
我正试图通过以下方式访问它
class clsSharedUserController extends clsController{
// construct
public function __construct($smarty) {
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
// ad details used for messages
public function getUserReviews($userReviews){
$this->o_clsSharedAdsController->getAdDetailsForMessage(1);
}
}
老实说,我希望得到我的1 echo ed,但我得到了以下错误:
Fatal error: Uncaught Error: Call to a member function getAdDetailsForMessage() on null in /home/vhosts/gamermarket.nl/httpdocs/includes/controllers/shared/clsSharedUserController.php:124
Stack trace:
#0 /home/vhosts/gamermarket.nl/httpdocs/includes/controllers/shared/clsSharedUserController.php(68): clsSharedUserController->getUserReviews(Array)
#1 /home/vhosts/gamermarket.nl/httpdocs/includes/controllers/clsReviewController.php(17): clsSharedUserController->getUserReviewsFromUsersId('0000000001')
#2 /home/vhosts/gamermarket.nl/httpdocs/reviews.php(10): clsReviewController->getReviews()
#3 {main} thrown in /home/vhosts/gamermarket.nl/httpdocs/includes/controllers/shared/clsSharedUserController.php on line 124
我使用一个PDO类来查询数据,它们的设置方式与此CLSCOcontroller相同。我可能缺少一些正确设置的逻辑,以便在所有类中共享数据,而不总是创建新实例。您应该能够创建一个类的实例并在其他类之间共享它,而不是?我认为您的主类不应该在构造中创建新的子类 在clsSharedUserController中
class clsController{
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
}
class clsSharedUserController extends clsController{
protected $o_clsSharedAdsController;
// construct
public function __construct($smarty) {
parent::__construct($smarty);
$this->o_clsSharedAdsController = new clsSharedAdsController($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$this->o_clsSharedAdsController->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
}
class clsController{
protected $o_smarty;
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
public function getSharedUser()
{
return new clsSharedUserController($this->o_smarty);
}
public function getSharedAds()
{
return new clsSharedAdsController($this->o_smarty);
}
}
class clsSharedUserController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$sharedAds = $this->getSharedAds();
$sharedAds->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
//use the method in share user class
public function someMethod(){
$sharedUser = $this->getSharedUser();
//TODO
}
}
在clsSharedUserController中
class clsController{
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
}
class clsSharedUserController extends clsController{
protected $o_clsSharedAdsController;
// construct
public function __construct($smarty) {
parent::__construct($smarty);
$this->o_clsSharedAdsController = new clsSharedAdsController($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$this->o_clsSharedAdsController->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
}
class clsController{
protected $o_smarty;
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
public function getSharedUser()
{
return new clsSharedUserController($this->o_smarty);
}
public function getSharedAds()
{
return new clsSharedAdsController($this->o_smarty);
}
}
class clsSharedUserController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$sharedAds = $this->getSharedAds();
$sharedAds->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
//use the method in share user class
public function someMethod(){
$sharedUser = $this->getSharedUser();
//TODO
}
}
在CLSSharedsController中
class clsController{
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
}
class clsSharedUserController extends clsController{
protected $o_clsSharedAdsController;
// construct
public function __construct($smarty) {
parent::__construct($smarty);
$this->o_clsSharedAdsController = new clsSharedAdsController($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$this->o_clsSharedAdsController->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
}
class clsController{
protected $o_smarty;
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
public function getSharedUser()
{
return new clsSharedUserController($this->o_smarty);
}
public function getSharedAds()
{
return new clsSharedAdsController($this->o_smarty);
}
}
class clsSharedUserController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$sharedAds = $this->getSharedAds();
$sharedAds->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
//use the method in share user class
public function someMethod(){
$sharedUser = $this->getSharedUser();
//TODO
}
}
我认为你的主类不应该在新的子类内部构造 在clsSharedUserController中
class clsController{
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
}
class clsSharedUserController extends clsController{
protected $o_clsSharedAdsController;
// construct
public function __construct($smarty) {
parent::__construct($smarty);
$this->o_clsSharedAdsController = new clsSharedAdsController($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$this->o_clsSharedAdsController->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
}
class clsController{
protected $o_smarty;
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
public function getSharedUser()
{
return new clsSharedUserController($this->o_smarty);
}
public function getSharedAds()
{
return new clsSharedAdsController($this->o_smarty);
}
}
class clsSharedUserController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$sharedAds = $this->getSharedAds();
$sharedAds->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
//use the method in share user class
public function someMethod(){
$sharedUser = $this->getSharedUser();
//TODO
}
}
在clsSharedUserController中
class clsController{
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
}
class clsSharedUserController extends clsController{
protected $o_clsSharedAdsController;
// construct
public function __construct($smarty) {
parent::__construct($smarty);
$this->o_clsSharedAdsController = new clsSharedAdsController($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$this->o_clsSharedAdsController->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
}
class clsController{
protected $o_smarty;
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
public function getSharedUser()
{
return new clsSharedUserController($this->o_smarty);
}
public function getSharedAds()
{
return new clsSharedAdsController($this->o_smarty);
}
}
class clsSharedUserController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$sharedAds = $this->getSharedAds();
$sharedAds->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
//use the method in share user class
public function someMethod(){
$sharedUser = $this->getSharedUser();
//TODO
}
}
在CLSSharedsController中
class clsController{
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
}
class clsSharedUserController extends clsController{
protected $o_clsSharedAdsController;
// construct
public function __construct($smarty) {
parent::__construct($smarty);
$this->o_clsSharedAdsController = new clsSharedAdsController($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$this->o_clsSharedAdsController->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
}
class clsController{
protected $o_smarty;
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
public function getSharedUser()
{
return new clsSharedUserController($this->o_smarty);
}
public function getSharedAds()
{
return new clsSharedAdsController($this->o_smarty);
}
}
class clsSharedUserController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$sharedAds = $this->getSharedAds();
$sharedAds->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
//use the method in share user class
public function someMethod(){
$sharedUser = $this->getSharedUser();
//TODO
}
}
必须先创建clsSharedAdsController类的实例,然后才能使用其方法
o_clsSharedAdsController = new clsSharedAdsController($smarty);
o_clsSharedAdsController->getAdDetailsForMessage(1);
必须先创建clsSharedAdsController类的实例,然后才能使用其方法
o_clsSharedAdsController = new clsSharedAdsController($smarty);
o_clsSharedAdsController->getAdDetailsForMessage(1);
如果要在CLSSharedsController中使用某些clsSharedUserController的方法 并在clsSharedUserController中使用一些CLSSharedAddController的方法 你需要重新设计这个类 在CLS控制器中
class clsController{
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
}
class clsSharedUserController extends clsController{
protected $o_clsSharedAdsController;
// construct
public function __construct($smarty) {
parent::__construct($smarty);
$this->o_clsSharedAdsController = new clsSharedAdsController($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$this->o_clsSharedAdsController->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
}
class clsController{
protected $o_smarty;
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
public function getSharedUser()
{
return new clsSharedUserController($this->o_smarty);
}
public function getSharedAds()
{
return new clsSharedAdsController($this->o_smarty);
}
}
class clsSharedUserController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$sharedAds = $this->getSharedAds();
$sharedAds->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
//use the method in share user class
public function someMethod(){
$sharedUser = $this->getSharedUser();
//TODO
}
}
在clsSharedUserController中
class clsController{
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
}
class clsSharedUserController extends clsController{
protected $o_clsSharedAdsController;
// construct
public function __construct($smarty) {
parent::__construct($smarty);
$this->o_clsSharedAdsController = new clsSharedAdsController($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$this->o_clsSharedAdsController->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
}
class clsController{
protected $o_smarty;
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
public function getSharedUser()
{
return new clsSharedUserController($this->o_smarty);
}
public function getSharedAds()
{
return new clsSharedAdsController($this->o_smarty);
}
}
class clsSharedUserController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$sharedAds = $this->getSharedAds();
$sharedAds->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
//use the method in share user class
public function someMethod(){
$sharedUser = $this->getSharedUser();
//TODO
}
}
在CLSSharedsController中
class clsController{
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
}
class clsSharedUserController extends clsController{
protected $o_clsSharedAdsController;
// construct
public function __construct($smarty) {
parent::__construct($smarty);
$this->o_clsSharedAdsController = new clsSharedAdsController($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$this->o_clsSharedAdsController->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
}
class clsController{
protected $o_smarty;
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
public function getSharedUser()
{
return new clsSharedUserController($this->o_smarty);
}
public function getSharedAds()
{
return new clsSharedAdsController($this->o_smarty);
}
}
class clsSharedUserController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$sharedAds = $this->getSharedAds();
$sharedAds->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
//use the method in share user class
public function someMethod(){
$sharedUser = $this->getSharedUser();
//TODO
}
}
如果要在CLSSharedsController中使用某些clsSharedUserController的方法 并在clsSharedUserController中使用一些CLSSharedAddController的方法 你需要重新设计这个类 在CLS控制器中
class clsController{
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
}
class clsSharedUserController extends clsController{
protected $o_clsSharedAdsController;
// construct
public function __construct($smarty) {
parent::__construct($smarty);
$this->o_clsSharedAdsController = new clsSharedAdsController($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$this->o_clsSharedAdsController->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
}
class clsController{
protected $o_smarty;
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
public function getSharedUser()
{
return new clsSharedUserController($this->o_smarty);
}
public function getSharedAds()
{
return new clsSharedAdsController($this->o_smarty);
}
}
class clsSharedUserController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$sharedAds = $this->getSharedAds();
$sharedAds->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
//use the method in share user class
public function someMethod(){
$sharedUser = $this->getSharedUser();
//TODO
}
}
在clsSharedUserController中
class clsController{
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
}
class clsSharedUserController extends clsController{
protected $o_clsSharedAdsController;
// construct
public function __construct($smarty) {
parent::__construct($smarty);
$this->o_clsSharedAdsController = new clsSharedAdsController($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$this->o_clsSharedAdsController->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
}
class clsController{
protected $o_smarty;
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
public function getSharedUser()
{
return new clsSharedUserController($this->o_smarty);
}
public function getSharedAds()
{
return new clsSharedAdsController($this->o_smarty);
}
}
class clsSharedUserController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$sharedAds = $this->getSharedAds();
$sharedAds->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
//use the method in share user class
public function someMethod(){
$sharedUser = $this->getSharedUser();
//TODO
}
}
在CLSSharedsController中
class clsController{
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
}
class clsSharedUserController extends clsController{
protected $o_clsSharedAdsController;
// construct
public function __construct($smarty) {
parent::__construct($smarty);
$this->o_clsSharedAdsController = new clsSharedAdsController($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$this->o_clsSharedAdsController->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
}
class clsController{
protected $o_smarty;
public function __construct($smarty){
if (is_object($smarty)) {
$this->o_smarty = $smarty;
} else {
throw new Exception("Smarty not set!");
}
}
public function getSharedUser()
{
return new clsSharedUserController($this->o_smarty);
}
public function getSharedAds()
{
return new clsSharedAdsController($this->o_smarty);
}
}
class clsSharedUserController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getUserReviews($userReviews){
$sharedAds = $this->getSharedAds();
$sharedAds->getAdDetailsForMessage(1);
}
}
class clsSharedAdsController extends clsController{
// construct
public function __construct($smarty) {
parent::__construct($smarty);
}
// ad details used for messages
public function getAdDetailsForMessage($ads_id){
echo $ads_id;
}
//use the method in share user class
public function someMethod(){
$sharedUser = $this->getSharedUser();
//TODO
}
}
您没有将
$this->o_clssharedascontroller
设置为clssharedascontroller
中的任何内容。我不知道你期望它是什么,但如果你不设置/初始化它,它就不会有任何方法或数据p当我这样做时,我得到了:致命错误:允许的内存大小为134217728字节(试图分配262144字节),在/home/vhosts/gamermarket.nl/httpdocs/includes/controllers/shared/clsSharedUserController.php的第6行,您没有将$this->o_clssharedDataController
设置为clsSharedUserController
中的任何内容。我不知道你期望它是什么,但如果你不设置/初始化它,它就不会有任何方法或数据p当我这样做时,我得到:致命错误:第6OK行的/home/vhosts/gamermarket.nl/httpdocs/includes/controllers/shared/clsSharedUserController.php中允许的内存大小为134217728字节(尝试分配262144字节),听起来不错,当我尝试创建$this->o_clsSharedUserController=new clsSharedUserController($smarty)的新实例时;在clsSharedAdsController中,我遇到了一个致命错误:允许的内存大小为134217728字节(尝试分配262144字节)。由于您卡在循环中,例如类a创建b和类b创建a(无限循环),那么在类之间共享数据的正确方法是什么?类A如何从B和B访问数据而不在两个类中启动?当我尝试创建$this->o_clsSharedUserController=new clsSharedUserController($smarty)的新实例时,Oke听起来不错;在clsSharedAdsController中,我遇到了一个致命错误:允许的内存大小为134217728字节(尝试分配262144字节)。由于您卡在循环中,例如类a创建b和类b创建a(无限循环),那么在类之间共享数据的正确方法是什么?在两个类中都没有初始化的情况下,类A如何从B和B访问数据!唯一不好的是我必须重构很多代码。但是,嘿,任何好的干净的代码:这是工作!唯一不好的是我必须重构很多代码。但是嘿,有什么好的干净代码吗