Anciennes révisionsLiens de retourExporter en PDFHaut de page Share via Share via... Twitter LinkedIn Facebook Pinterest Telegram WhatsApp Yammer RedditDerniers changementsSend via e-MailImprimerPermalien × source: http://www.developer.com/lang/php/article.php/3636686 CREATE TABLE players ( id SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(50) NOT NULL, position VARCHAR(25) NOT NULL, team_id SMALLINT(6) ) CREATE TABLE teams ( id SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50) NOT NULL, ) /app/controllers/players_controller.php <?php class PlayersController extends AppController { var $scaffold; } ?> teams_controller.php <?php class TeamsController extends AppController { var $scaffold; } ?> /app/models/player.php <?php class Player extends AppModel { var $name = 'Player'; var $belongsTo = array('Team' => array('className' => 'Team', 'conditions' => '', 'order' => '', 'foreignKey' => 'team_id' ) ); } ?> Note the $belongsTo array has been defined, mapping the team_id column to the Team model. Finally, we need to define the Team model so CakePHP knows which column should be displayed as a result of mapping to the teams table. Place the following code in a file named team.php and save it to the /app/models/ directory: team.php <?php class Team extends AppModel { var $name = 'Team'; var $displayField = 'name'; } ?> http://localhost/cake/teams/add http://localhost/cake/teams/ info/tutoriel_cakephp_scaffold_join_tables.txt Dernière modification : 2018/07/18 09:46de radeff S'identifier