I’ve been trying for days to get this code working and can’t seem to get rid of this syntax error:
Unexpected } on the last line of the file. WHY?!!!?!?!
Someone mentioned I’m usually missing something like a ) or ; above that line, but I’ve been checking brackets, parentheses, etc. and can’t figure out what I’m missing. Help please?
<?php
namespace backend\controllers;
use Yii;
use backend\models\Registrations;
use backend\models\Players;
use backend\models\search\RegistrationsSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\helpers\Json;
use yii\helpers\ArrayHelper;
use yii\base\Exception;
/**
* RegistrationController implements the CRUD actions for registration and players models.
*/
class RegistrationController extends Controller
{
/*public function actionCreate()
{
$registration = new Registrations();
$players = [];
for ($i = 0; $i < 5; $i++) {
$players[] = new Players();
}
if ($registration->load(Yii::$app->request->post())) {
$registration->save();
}
if (Players::loadMultiple($players, Yii::$app->request->post())) {
foreach ($players as $player) {
$player->regsitrationID = $registration->ID;
$player->save();
}
}
return $this->render('create',[
'registration'=>$registration,
'players' => $players,
]);
}
}*/
public function actionCreate()
{
$registrations = new Registrations;
$player1 = new Players;
$player2 = new Players;
$player3 = new Players;
$player4 = new Players;
if ($registrations->load(Yii::$app->request->post()) && $player1->load(Yii::$app->request->post()) && $player2->load(Yii::$app->request->post()) && $player3->load(Yii::$app->request->post()) && $player4->load(Yii::$app->request->post()) && Model::validateMultiple([$registrations, $player1, $player2, $player3, $player4])) {
$registrations->save(false); // skip validation as model is already validated
$player1->registrationID = $registrations->id; // no need for validation rule on user_id as you set it yourself
$player1-save(false);
$player2->registrationID = $registrations->id; // no need for validation rule on user_id as you set it yourself
$player2-save(false);
$player3->registrationID = $registrations->id; // no need for validation rule on user_id as you set it yourself
$player3-save(false);
$player4->registrationID = $registrations->id; // no need for validation rule on user_id as you set it yourself
$player4-save(false);
return $this->redirect(['players/index', 'registrationID' => $registrations->id]);
} else {
return $this->render('create', [
'registrations' => $registrations,
'player1' => $player1,
'player2' => $player2,
'player3' => $player3,
'player4' => $player4,
]);
}
}