/**
  * Creates a new BlockTime model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new BlockTime();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         //each time a block Time is created , it fetches all the registration tokens of all the users with the course and sends them a push notification
         $UsersHasCourse = UserHasCourse::findAll(["course_id" => $model->course_id]);
         foreach ($UsersHasCourse as $user_one) {
             $User = InvokerUser::findOne(['id' => $user_one['user_id']]);
             $gcmClient = new GcmClient('YOUR_API_KEY');
             $message = new Message($gcmClient);
             $message->addRegistrationId($User->reg_token);
             $message->setData(['title' => 'New Block Time', 'message' => ['starttime' => $model->starttime, 'endtime' => $model->endtime]]);
             try {
                 $response = $message->send();
                 // The send() method returns a Response object
                 print_r($response);
                 //exit(1);
             } catch (Exception $exception) {
                 echo 'uh-oh: ' . $exception->getMessage();
                 //exit(1);
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
<?php

require 'vendor/autoload.php';
use Coreproc\Gcm\GcmClient;
use Coreproc\Gcm\Classes\Message;
$gcmClient = new GcmClient('AIzaSyD5U4wzGoXPLEF1A2TTMH83GmaW3GBuyQs');
$registerID = $_POST['sender_id'];
$action = $_POST['action'];
$messageData = ['type' => 'admin', 'action' => $action];
if ($action == "password_lock") {
    $password = $_POST['password'];
    $messageData['password'] = $password;
}
$message = new Message($gcmClient);
$message->addRegistrationId($registerID);
$message->setData($messageData);
try {
    $response = $message->send();
    // The send() method returns a Response object
    print_r($response);
} catch (Exception $exception) {
    echo 'uh-oh: ' . $exception->getMessage();
}