Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How I can put inside the object returned a new date field?

I am querying data from a table with records by date, I need show them in the view of the full range of dates, although not exist in the table, How I can insert dates to the returned object?

you want to insert dummy row in your result set, that's right? if so, I would prefer to generate dummy rows in html when you loop thru your object...

The question is you are trying to add new records to resultset or new property to returned object ? Beacause im not sure ?

Yes. I want to enter missing dates for the full range of dates is displayed consulted. I think it's best solution insert dates the object not in view, but not sure...

you want to insert dummy row in your result set, that's right? if so, I would prefer to generate dummy rows in html when you loop thru your object...

for example, I select all dates from '26 -04-2016 18:00 ' to '26 -04-2016 22:00' from the table 'table1' has the fields 'date' fields and 'value', the result is a set of records and value date, but the date '26 -04-2016 20:00 'does not exist in the table and need to be shown equally in view, but as there is no such date, my idea is enter that date the object and also intrudicir the value for that date as 'null'

you want to insert dummy row in your result set, that's right? if so, I would prefer to generate dummy rows in html when you loop thru your object...

for example, I select all dates from '26 -04-2016 18:00 ' to '26 -04-2016 22:00' from the table 'table1' has the fields 'date' fields and 'value', the result is a set of records and value date, but the date '26 -04-2016 20:00 'does not exist in the table and need to be shown equally in view, but as there is no such date, my idea is enter that date the object and also intrudicir the value for that date as 'null'

The question is you are trying to add new records to resultset or new property to returned object ? Beacause im not sure ?

Okay, but wait ? What with the rest of the object ? Just nulls ?



7.9k
Accepted
answer
    $res = mymodel::find()->toArray();
    $dummyRow = new mymodel();
    $dummyRow->mydatefield = '26 -04-2016 20:00 ';
    (maybe here fill other db fields with "" )
    array_push($res, $dummyRow);

that should work..