public function sendMessage() { if (Yii::$app->request->isAjax) { $post = Yii::$app->request->post(); if (isset($post['id']) && $post['id'] > 0) { $station = Station::findOne($post['id']); $ip = $station['ip']; $port = $station['port']; if ($ip != '' && $port != '') { $client = new Client(); $init = $client->init($ip, $port); if ($init) { $send = $client->send($post['message']); if ($send) { print $client->returnMessage; } else { print $client->error; } } else { print $client->error; } } } } print 'failed'; }