2016-09-01 5 views
3

私はを2台のコントローラで2台のモデルを使用しています。そのうちの1つはデータベースモデル(モデル)です。別のモデルはsmsを送信するためのものです(smsModel)です。yii2でSMSを送信する

私はsmsModelに問題があります。

私は私の結果では、このエラーを得た:

Class 'fcadmin\models\SoapClient' not found 

私はそれを解決することができますか?

マイコントローラ:

public function actionCreate($id) { 

     $model = new Requestresult(); 
     $smsModel = new SmsSender(); 
     $request_model = Request::findOne(['id' => $id]); 

     $model->CodeKargah = $request_model->CodeKargah; 
     $model->month = $request_model->month; 
     $model->trackingCode = $request_model->trackingCode; 
     if ($model->load(Yii::$app->request->post()) && $model->save()) { 
      $smsModel->sendSms('09193452126', 'sdf'); 
      return $this->redirect(['view', 'id' => $model->id]); 
     } else { 
      return $this->render('create', [ 
         'model' => $model, 
      ]); 
     } 
    } 

smsModel:名前空間についてまで読む必要が

public function sendSms($to, $text) { 
    $options = [ 
     'login' => 'myusername', 
     'password' => 'mypassword' 
    ]; 
    $client = new SoapClient('http://sms.hostiran.net/webservice/?WSDL', $options); 
    $messageId = $client->send($to, $text); 
    sleep(3); 
    return ($client->deliveryStatus($messageId)); 
} 

答えて

3

。名前空間にいて、PHPにグローバル名前空間を使用するよう指示していない場合は、現在の名前空間の名前xのクラスを探します。

あなたの場合、new \SoapClientを使用する必要があります。

+0

ありがとうございます。できます –