0

我有控制器和模型。我正在修改模型中的变量值,但它没有反映在控制器中,我在 OOP 方面不是那么专家。

// controller class structure
class Leads_import extends CI_Controller {

public $total = 0;

  public function import(){
   $this->xml_model->imsert();
   echo $this->total; 
  }
}

// model class structure
class xml_model extends CI_Model {

   public function insert(){
      this->total = 10; 
   }
}
4

2 回答 2

0

试试这个:

// controller class structure
class Leads_import extends CI_Controller {

public $total = 0;

  public function import(){
   $this->total = $this->xml_model->imsert();
  }
}

模型:

// model class structure
class xml_model extends CI_Model {

   public function insert(){
      return 10; 
   }
}
于 2012-06-19T13:29:03.583 回答
0

您必须检查$totalofxml_model或让它更新$totalof Leads_import。您在控制器中读取了错误的变量,它永远不会更新。

这是我在不知道您真正想要做什么的情况下提出的建议:

class Leads_import extends CI_Controller {
   public $total = 0;
   public function import(){
     $this->xml_model->insert();
     // Read xml_model total and assign to Leads_import total
     $this->total = $this->xml_model->total; 
     echo $this->total; 
  }
}

class xml_model extends CI_Model {
   public $total = 0;
   public function insert(){
      $this->total = 10; // update xml_model total
   }
}
于 2012-06-19T13:29:15.470 回答