ตอบ

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.
ชื่อ:
อีเมล์:
หัวข้อ:
ไอค่อนข้อความ:

แนบไฟล์:
(Clear Attachment)
(แนบไฟล์เพิ่ม)
Restrictions: 4 per post, maximum total size 1024KB, maximum individual size 512KB
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:
พิมพ์เป็นภาษาไทย "FoxPro":

shortcuts: กด alt+s เพื่อตั้งกระทู้ หรือ alt+p แสดงตัวอย่าง


สรุปหัวข้อ

ข้อความโดย: อั๋น ทรงวุฒิ
« เมื่อ: 29 กรกฎาคม 2021, 10:47:19 PM »

ใช้ Gii สร้าง Models ก่อน

ไฟล์ :: Controller

อ้างถึง
use app\models\Billist;   // เรียก Model ที่สร้างเอามาใช้ค้นข้อมูล

public function actionIndex($id=0)
{
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     if ($id==0) // ไม่ระบุ id
     {
        $billist = Billist::find()->all();
        if (count($billist)>0)  return $billist;
        else return array('data'=>'None');
     }
     else // ถ้าระบุ id มา ให้ไปหามาตอบ
     {
        $billist=Billist::find($id)->one(); 
        return $billist;
     }
}