CI4 MVC DB accesses are often made in the controller in the examples |
(01-04-2021, 05:15 AM)includebeer Wrote: This is explained in the tutorial in the user guide:In the tutorial, the "save" method is called in the "news" controller. This is a database access and according to my understanding it should only take place in the "model". Am I correct? public function create() { $model = new NewsModel(); if ($this->request->getMethod() === 'post' && $this->validate([ 'title' => 'required|min_length[3]|max_length[255]', 'body' => 'required' ])) { $model->save([ <------------------ 'title' => $this->request->getPost('title'), 'slug' => url_title($this->request->getPost('title'), '-', TRUE), 'body' => $this->request->getPost('body'), ]); echo view('news/success'); } else { echo view('templates/header', ['title' => 'Create a news item']); echo view('news/create'); echo view('templates/footer'); } } |
Messages In This Thread |
CI4 MVC DB accesses are often made in the controller in the examples - by divebase - 01-04-2021, 05:04 AM
RE: CI4 MVC DB accesses are often made in the controller in the examples - by includebeer - 01-04-2021, 05:15 AM
RE: CI4 MVC DB accesses are often made in the controller in the examples - by divebase - 01-06-2021, 04:11 AM
RE: CI4 MVC DB accesses are often made in the controller in the examples - by divebase - 01-04-2021, 07:25 AM
RE: CI4 MVC DB accesses are often made in the controller in the examples - by includebeer - 01-06-2021, 05:50 AM
|