Lo que estoy tratando de hacer es asignar un jugador a un equipo, pero no estoy seguro de cómo hacerlo.
Estas son las clases :
team.php
Código PHP:
Ver original
class Team { private $teams; private $name; public function __construct($name){ $this->name = $name; } public function getName(){ return $this->name; } public function addTeam($oneTeam){ $this->teams[] = $oneTeam; return $this; } public function printTeams(){ echo "<br>"."<br>"; echo "<b>Teams available</b>"; echo "<br>"."<br>"; foreach($this->$teams as $team){ echo $team->getName() . " "; echo "<br>"; } } } // Load the team data of the session and if it does not exist create a new team. function loadDataTeam(){ } // Save the team data in the session. function saveDataTeam($team){ $_SESSION['team'] = $team; } $team = new Materia(); //teams by default. $team->addTeam(new Team("Team 1")); $team->addTeam(new Team("Team 2")); $team->addTeam(new Team("Team 3")); saveDataTeam($team); ?>
player.php
Código PHP:
Ver original
include_once("team.php"); class Player { private $players; private $name; public function __construct($name){ $this->name = $name; } public function getName(){ return $this->name; } public function addPlayer($onePlayer){ $this->players[] = $onePlayer; return $this; } public function printPlayers(){ foreach($this->players as $player){ echo $player->getName() . " "; echo "<br>"; } } } // Load the player data of the session and if it does not exist create a new player. function loadDataPlayer(){ } // Save the player data in the session. function saveDataPlayer($player){ $_SESSION['player'] = $player; } $player = new Player(); //Players by default. $player->addPlayer(new Player("Player 1")); $player->addPlayer(new Player("Player 2")); $player->addPlayer(new Player("Player 3")); saveDataPlayer($player); ?>
index.php
Código PHP:
Ver original
<html> <head> <title>Asignar jugador a equipo</title> <meta charset="UTF-8"/> </head> <body> <?php form(); include_once("team.php"); include_once("player.php"); $player = new Player(); $team = new Team(); $player = loadDataPlayer(); $team = loadDataTeam(); function form(){ echo '<FORM METHOD="POST" style="text-align: center; margin-top: 73px;"> <h2>Asignar jugador a equipo</h2> <label>Introduce el nombre del jugador : </label><INPUT class="form" TYPE = "text" NAME = "name"> <br> <label>Introduce el nombre del equipo : </label><INPUT class="form" TYPE = "text" NAME = "team"> <br><br> <INPUT class="form" TYPE = "submit" VALUE = "Send" name="action"> </ FORM>'; } ?> </body> </html>