Answer the question
In order to leave comments, you need to log in
How to populate the contents of variables while executing if-else statements?
Good evening!
The action of one of my Yii2 controllers I wrote consists of an implemented microarchitecture web service that only works on JSON.
On the first lines, I initialized this variable:
$serviceResponse = NULL;
And below it are if-else statements that fill the variable separately depending on the user's query parameters.
And my response itself is built like this:
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return ["response" => $serviceResponse];
{response: []}
Answer the question
In order to leave comments, you need to log in
The code needs to be heavily refactored, it is terribly readable.
For your question specifically
1) look in xdebug to see if the dots work.
2) Why are you working with json like a string?
With response json in yii2, you must return an array.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question