I have a CRUD application and everything works well except editing an asset as shown here.
When I click on edit, all the fields are populated with the data about the asset except for two fields, Date Of Purchase
and Date Of Entry
as shown here enter image description here. The two fields are using date pickers.
Here is were it gets interesting, when I echo the array <?= $asset ?>
in the edit.ctp
as passed from the edit()
method in the AssetsController.php
, this is what the echo shows;
{ "id": 4, "school_unit_id": 35, "asset_source_id": 19, "asset_description": "iPhone 12", "date_of_entry": "2021-10-11T00:00:00+00:00", "date_of_purchase": "2021-10-08T00:00:00+00:00", "grn_number": "KBHBBH62", "name_of_supplier": "SEAGHON TECH", "serial_number": "YTDIYTFYUFOGOOAA", "location": "CICT", "asset_category_id": 22, "asset_group_class_id": 49, "full_asset_number": "GGFUYG66", "condition_id": 12, "asset_status_id": 13, "value": "20,000", "custodian_name": "JOE BANDA", "custodian_phone": "0966010101", "custodian_email": "bursar@unza.zm", "created": "2021-05-31T08:45:17+00:00", "modified": "2021-10-12T10:45:11+00:00", "created_by": "admin", "asset_status": { "id": 13, "name": "OPERATIONAL", "created_by": "admin" }, "asset_group": { "id": 49, "asset_group": "Mobile Phone / Office Extension / Land Phone", "category_id": 22, "created": "2021-05-06T16:48:40+00:00", "modified": "2021-05-06T16:48:40+00:00", "created_by": "admin" }, "asset_source": { "id": 19, "name": "Procurement", "created_by": "" }, "asset_category": { "id": 22, "category": "EQUIPMENT", "created": "2021-04-28T08:27:51+00:00", "modified": "2021-10-06T09:48:30+00:00", "created_by": "admin" }, "asset_condition": { "id": 12, "condition_name": "New", "created": "2021-03-31T10:40:43+00:00", "modified": "2021-03-31T10:40:43+00:00", "created_by": "admin" }, "school_unit": { "id": 35, "school_unit_name": "CENTER FOR INFORMATION AND COMMUNICATION TECHNOLOGIES", "created": "2021-03-31T10:18:42+00:00", "modified": "2021-03-31T10:18:42+00:00", "created_by": "admin" } }
Clearly, the date_of_purchase
and the date_of_entry
date values are displaying. With that, this is how am echoing these dates on the fields in the form.
<div class="col-sm-4">
<?= $this->Form->input('date_of_purchase', array('type' => 'date', 'required' => 'required', 'class' => 'form-control date', 'value' => ($asset->date_of_purchase))) ?>
</div>
And
<div class="col-sm-4">
<?= $this->Form->input('date_of_entry', array('type' => 'date', 'required' => 'required', 'class' => 'form-control date', 'value' => ($asset->date_of_entry))) ?>
</div>
But the date values are not displaying in the edit form. I have tried storing the date in another variable, then strtotime()
it, still nothing. I don't know were am missing it.