如何使用extend从其他类访问变量?

Hello I would like to ask how can I get the $manufacturer and $id from the function postData() which included with other class. So I can pass it to my model. Thank you.

class postDataManager{

   public function postData(){
       $manufacturer = $_POST['manufacturer'];
       $id = $_POST['id'];  
   }
}

class manufactureController extends postDataManager{

  private $model;

    public function __construct(){
       $this->model = new manufacturerModel();
       $postDataManager= new postDataManager();
    }

   public function addManufacturer(){ //get the add function
      //here i need access for the variable $manufaturer from class postData function
       $this->model->addProcess($manufacturer);     
   }

   public function updateManufacturer(){ //get the update function
      //here i need access for the variable $manufaturer and $id from class postData function
       $this->model->updateProcess($id, $manufacturer);
   }
}

Currently those two variables are lost once the postData() method is left, since they belong to the local scope of the method. You need to define properties for them.

Take a look at this modified example:

<?php
class manufacturerModel {
}

class postDataManager {
  protected $id;
  protected $manufacturer;

  public function __construct($manufacturer, $id) {
    $this->manufacturer = $manufacturer;
    $this->id = $id;  
  }
}

class manufactureController extends postDataManager {
  private $model;

  public function __construct($manufacturer, $id) {
    parent::__construct($manufacturer, $id);
     $this->model = new manufacturerModel();
  }

  public function addManufacturer() { //get the add function
     $this->model->addProcess($this->manufacturer);     
  }

  public function updateManufacturer() { //get the update function
     $this->model->updateProcess($this->id, $this->manufacturer);
  }

  public function echoContent() {
    echo sprintf("manufacturer: %s
id: %s
", $this->manufacturer, $this->id);
  }  
}

// some example values
$_POST['manufacturer'] = "Manufactum Ltd.";
$_POST['id'] = 17397394;

$controller = new manufactureController($_POST['manufacturer'], $_POST['id']);
$controller->echoContent();

Now those values are stored in a persistent manner inside the object. Since your second class extends the first class those properties are also part of objects instantiate from that derived class, so you can access them likewise using the $this reference, unless they have been declared private in that class.

The output of above demo code is:

manufacturer: Manufactum Ltd.
id: 17397394

These are the basics of OOP (object oriented programming), this is explained in every tutorial.

create property with name of $manufacturer and $id

class postDataManager{
   protected $manufacturer;
   protected $id;
   public function postData($manufacturer){
       $this->manufacturer = $_POST['manufacturer'];
       $this->id = $_POST['id'];  
   }
}

Now you can access with in child Class

You should declare $manufacturer and $id variables in postDataManager class and in postData function then use $this->manufacturer=$_POST['manufacturer']; and $this->id=$_POST['id'];