![]() |
Struckle with my model and the builder - "Call to a member function get() on null" - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Struckle with my model and the builder - "Call to a member function get() on null" (/showthread.php?tid=79232) |
Struckle with my model and the builder - "Call to a member function get() on null" - sprhld - 05-15-2021 Hello! I had the idea, to write a new program. I do this for fun, I am not a professional developer. I used CI3 at my last project 4 years ago, so I would like to have fun with CI4 now :-) But I struckle with my model. It was not easy to write data to the database and now I can't get it out of it ![]() So this is my latest code where I'm stuck... With this code, I get the message "Call to a member function get() on null" and I didn't found a solution. I tried the builder and without it (as you see)... The controller PHP Code: <?php And my model PHP Code: <?php Thank you! RE: Struckle with my model and the builder - "Call to a member function get() on null" - InsiteFX - 05-15-2021 Your redefining the database db and builder in your models constructor, the model already has the builder. just use this->builder where needed. These are already set in the model. You do not have to tell the builder the model name its in your variables. PHP Code: <?php RE: Struckle with my model and the builder - "Call to a member function get() on null" - sprhld - 05-15-2021 Thank you for your answer, what I did is the result of different approaches to solve my problem ![]() I changed my code to you suggestion and I still get the message "Call to a member function get() on null" and it points to "APPPATH/Models/EpocheModel.php at line 38" which is the line with "$this->builder" RE: Struckle with my model and the builder - "Call to a member function get() on null" - InsiteFX - 05-15-2021 Try this to see if your getting ant data back from the database. PHP Code: public function getAll() Get back to me and let me know that's just a fast way of testing a method for errors. I wont be back on until 11:30 pm tonight but I'll check here. RE: Struckle with my model and the builder - "Call to a member function get() on null" - includebeer - 05-15-2021 If you need to work with the query builder, you need to call the builder function, it’s not a variable: PHP Code: $builder = $this->builder(); But in your case, you don’t need your getAll() function, just call the findAll() function: PHP Code: $this->data['epochen'] = $this->model->findAll(); |