I'm creating a tournament-platform with CakePHP. Currently I've created the following tables, models and controller which work perfectly: Tournaments, Users, and Teams.
I've created a "Tournamentuser" table, controller & model as well, where the tournament_id, user_id and team_id is stored.
Then when using View.ctp under Tournaments, it should display the User.Username & Team.Username in relation to the Tournamentuser. As of now, I have only managed to retrieve the id's from the table via. a foreach(.. as ..). I can see in the CakePHP query that it retrieves the data, I just don't know how to print it.
I suppose you already know this but in CakePHP the conventions are:
If for example we need a relation: tournament-user we must follow the conventions(in CakePHP 2+):
If all the above conventions are followed before you can have your relation, tournaments-users you must define the relation between the two tables.
Here you can find more details on how to do this: http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html
If everything is done correctly until this point, you can now query the TournamentsUser Model.
$data = $this->TournamentsUser->find('all');
debug($data);
$size = count($data);
for($i=0; $i<$size; ++i) {
debug($data[$i]);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With