Struckle with my model and the builder - "Call to a member function get() on null" |
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 Here is my code to ask you for a review and feedback, how I should do it. I know, there are always different ways to the goal but I would like to have all DB-operations in my model and use the controller just as a "conductor" - as the most how-tos are describe CRUD-operations. And: I do it that way too, also without success. 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!
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 What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Thank you for your answer, what I did is the result of different approaches to solve my problem Every how-to did something new...
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"
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. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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();
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/ |
Welcome Guest, Not a member yet? Register Sign In |