<?php class CI_Controller { public function __construct() { } public function post($wl) { $data = []; foreach (array_keys($wl) as $f) { $data[$f] = $_POST[$f] ?? null; } return $data; } } class Search extends CI_Controller { public object $SearchModel; public function __construct() { parent::__construct(); $this->SearchModel = new Search_model(); $whitelist = get_object_vars($this->SearchModel); // var_export($whitelist); foreach ($this->post($whitelist) as $prop => $val) { $this->SearchModel->$prop = $val; } } public function test() { $this->SearchModel->searchByCategory(); } } class CI_Model { public function __construct() { } } class Search_model extends CI_Model { public ?int $productId = null; public ?string $productName = null; public ?string $category = null; public ?string $datetime = null; public ?int $userId = null; public function __construct() { parent::__construct(); //$this->load->database(); } public function searchByCategory() { var_dump(get_object_vars($this)); /* return $this->db->get_where('products', ['category' => $this->category])->result(); */ } } $_POST = ['productId' => '8', 'category' => 'foo']; (new Search())->test();
You have javascript disabled. You will not be able to edit any code.