Cara menampilkan response full json di yii2
Hay kawan2 yang hebat, selamat datang di blogger saya lagi. Siapakah saya, saya Arbahud Rio Daroyni orang dari sidoarjo yg ga terlalu pintar ngoding tapi selalu belajar Hehehe.
Oke, kali ini saya nyoba nulis2 bagi teman2 yang baru memulai yii2 dan masih bingung dengan cara menampilkan respose full json di yii2.
Langsung saja kodingannya, Saya asumsikan disini kita pakai di SiteController :
public function actionResponseJson()
{
$loremstr = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.";
$loremarr = array();
$json=explode(" ",$loremstr);
foreach ($json as $key => $value) {
array_push($loremarr, array(
"Lorem-" . $key => $value
));
}
Yii::$app->response->format = Response::FORMAT_JSON;
return [
'lorem-str' => $loremstr,
'lorem-array' => $loremarr
];
}
jadi langsung saja ketik alamat {{base-url}}/site/response-json
dan akan keluar seperti ini

Salam White Hat Indonesia
Regard
R&D Studio
Oke, kali ini saya nyoba nulis2 bagi teman2 yang baru memulai yii2 dan masih bingung dengan cara menampilkan respose full json di yii2.
Langsung saja kodingannya, Saya asumsikan disini kita pakai di SiteController :
public function actionResponseJson()
{
$loremstr = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.";
$loremarr = array();
$json=explode(" ",$loremstr);
foreach ($json as $key => $value) {
array_push($loremarr, array(
"Lorem-" . $key => $value
));
}
Yii::$app->response->format = Response::FORMAT_JSON;
return [
'lorem-str' => $loremstr,
'lorem-array' => $loremarr
];
}
jadi langsung saja ketik alamat {{base-url}}/site/response-json
dan akan keluar seperti ini
Salam White Hat Indonesia
Regard
R&D Studio
Komentar
Posting Komentar