Dear opencart gurus help with the question. How to make in my controller a request to the database for writing, deleting, updating, how can I not understand.
1 answer
Easy! Open the source code of any controller and read. In short: OpenCart uses the MVC principle, that is, the logic of the work is divided into parts. The controller processes the data, receiving / writing data in the model, and the data is displayed using views. Suppose we did controller/catalog/ctrl.php , then it is desirable to make a model/catalog/ctrl.php . In the model we make requests, and in the controller we process the results of the requests. Controller:
$this->load->model('catalog/ctrl'); $results = $this->model_catalog_ctrl->getRes(); Or so:
$this->load->model('catalog/ctrl'); $this->model_catalog_ctrl->delRes(); Model:
public function getRes() { $sql = "SELECT * FROM " . DB_PREFIX . ""; $query = $this->db->query($sql); return $query->rows; } Or so:
public function delRes() { $this->db->query("DELETE * FROM " . DB_PREFIX . "") } - and
inserthde ??? and it was also cool to give an example of passing parameters - tCode - Mmm, is it sarcasm or is it really necessary? Opening any OC controller you can see examples for all cases. - Andrew Hobbit
- not sarcasm, though I would like to see if there is a project on opencart, I would like to know it, I already added - tCode
|