第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從控制器返回數(shù)據(jù) - Codeigniter

從控制器返回數(shù)據(jù) - Codeigniter

PHP
開滿天機 2023-04-28 14:36:04
我試圖將數(shù)據(jù)返回到我的變量 $item_id 但變量返回空。我沒有以正確的方式返回數(shù)據(jù)嗎??item_id 應返回來自 serverMonitor.php 中的索引函數(shù)的“Alert”。請指教。謝謝項目.php function rest_state()  {     $id = 1;     $item_id =  $this->pass_to_res($id);     return $item_id //this should return "Alert"  }function pass_to_res($id)   {      $url = "https://example.com/serverMonitor?id=$id";      $ch = curl_init();      curl_setopt($ch, CURLOPT_URL, $url);      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");      $result = curl_exec($ch);      curl_close ($ch);      return $result;   }serverMonitor.php function index() {        $id = htmlentities($_GET['id']);        $word = "Alert";        return $word;    }
查看完整描述

1 回答

?
繁星點點滴滴

TA貢獻1803條經驗 獲得超3個贊

函數(shù)的返回值并不總是對訪問者可見。您應該使用 echo、print 或 print_r。


 function index() {

        $id = htmlentities($_GET['id']);

        $word = "Alert";

        echo $word;

        return true;

    }

你也可以使用 JSON with json_encode 來編碼


function index() {

            $id = htmlentities($_GET['id']);

            $word = "Alert";

            echo json_encode(['word' => $word]);

            return true;

        }

和 json_decode 解碼:


function pass_to_res($id)

   {

      $url = "https://example.com/serverMonitor?id=$id";

      $ch = curl_init();

      curl_setopt($ch, CURLOPT_URL, $url);

      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");

      $result = curl_exec($ch);

      curl_close ($ch);


      $result = json_decode($result);

      return isset($result['word']) ? $result['word'] : false;

   }


查看完整回答
反對 回復 2023-04-28
  • 1 回答
  • 0 關注
  • 168 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號