S
S
skajtersen2017-06-01 19:18:10
Yii
skajtersen, 2017-06-01 19:18:10

How to pass data from active form to sql query?

Suppose there is a sql query

Yii::$app->db->createCommand('SELECT ... WHERE date BETWEEN '2017-05-31 00:00:00' AND '2017-06-01 00:00:00'')->queryAll();

How to transfer the data entered in the active form instead of the dates specified in advance? That is, there are two fields "from" and "to" and by clicking submit, a request is executed with the entered data.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
skajtersen, 2017-06-02
@skajtersen

Like this: , and after the request

['date_from' => $date_from,  'date_to' => $date_to]

F
Fetur, 2017-06-01
@Fetur

Em. well. just do it!
1. Generate date on the client and send
2. For validation, you can use strtotime()
3. Insert in place of current dates.
4. Profit!!!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question