修改代码点火器模型中的变量值


modify variable value in codeigniter model

我有控制器和模型。 我正在修改模型中的变量值,但它没有反映在控制器中,我对 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; 
   }
}

试试这个:

// 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; 
   }
}

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

以下是我的建议,不知道你真正想做什么:

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
   }
}