How to understand entities, save, hasChanged |
(05-28-2024, 04:16 AM)spreaderman Wrote:(05-27-2024, 11:16 AM)ozornick Wrote: You can change the fill() method by filtering the array_filter() array of $data and allowing only $attributes from the model Something like this; PHP Code: $attributes_matching_from_new_fill = array_filter($new_fill, function ($value, $key) use ($attributes) { where attributes_matching_from_new_fill - is the new associative array that matches $attribute ($attributes = $this->OsmSkiResortModel->allowedFields) and $new_fill is the unfiltered associative array of the submitted data. Seems to work. Thank you.
I thought it was working but not so. I am getting the following error:
Error Call to a member function fill() on null It is related to: APPPATH/Controllers/Admin/Ski/Ski_Controller.php at line 312 I have highlight line 312 below which is indeed fill() PHP Code: public function qgis_data_update_aa_winter_sports_points_from_file(){ The output of the $attributes_matching_from_new_fill indeed returns the below: PHP Code: Array In line 294, actually nothing is returned because it is new data to be inserted. I though if there was no existing data save() would insert or delete. Any help here much appreciated.
Why double fill() ?
PHP Code: $this->OsmSkiResortModel->save($OsmSkiResort->fill($new_fill));
Simple CI 4 project for beginners codeigniter-expenses
(06-03-2024, 12:09 AM)ozornick Wrote: Why double fill() ? Thanks @ozornick. I can change that but it still fails at: PHP Code: $OsmSkiResort->fill($attributes_matching_from_new_fill); with the error PHP Code: "Call to a member function fill() on null" I tested attributes_matching_from_new_fill (see code above) and it contains this array: PHP Code: Array so it is puzzling what fill() fails.
Maybe I am not understanding ENTITIES properly?
The model is setup to returntype ENTITY. In my controller, do I need to load both the ENTITY and the MODEL? I am kind of confused as to when I need to use the model class or the entity class. use App\Models\QgisSkiResortModel; use App\Entities\QgisSkiResortEntity; For CRUD operations, if the below correct? example CREATE/UPDATE ============== For "create" or "update" If i used the model it would be something like; $userModel = new \App\Models\UserModel(); $userModel->insert($data); but if I used entity, would it be bellow same as above like: $userEntity = new \App\Models\UserEntity; $userEntity->insert($data); Not getting it.
See my pet project)
https://github.com/neznaika0/codeigniter...penses.php and filter properties https://github.com/neznaika0/codeigniter...el.php#L55 The model works with an entity. In this case, you need to create two objects: PHP Code: $entity = new UserEntity([...]);
Simple CI 4 project for beginners codeigniter-expenses
(05-25-2024, 09:42 PM)InsiteFX Wrote: 1) For one change to Camel Case. To me, "update_aa_winter..." is easier... (05-25-2024, 09:42 PM)InsiteFX Wrote: 2) You have an extra closing bracket on your if/else statement. I think the "} else {" belongs to the prior line The lack of indentation was the problem... PHP Code: if ($original_OsmSkiResort){
Thank you for all the pointer thus far! Really appreciated. Really having a hard time understanding entities. I still get an error Call to a member function fill()
PHP Code: use App\Models\QgisSkiResortModel; The above code still fail at $QgisResort->fill($attributes_matching_from_new_fill); and says "Call to a member function fill() on null", however, when I echo out $attributes_matching_from_new_fill I have the following; PHP Code: Array (
Read the error message carefully.
"Call to a member function fill() on null" That is, $QgisResort is null. |
Welcome Guest, Not a member yet? Register Sign In |