- Générer le module avec: generate:module frontend platform
- Routing:
platform:
url: /platform
param: { module: platform, action: index }
platform_show_platform:
url: /platform/:id/:name_platform_slug
class: sfDoctrineRoute
options:
model: platform
type: object
param:
module: platform
action: show
requirements:
id: \d+
sf_method: [get]
- Slug (Platform.class.php)
public function getNamePlatformSlug(){
return Videogames::slugify($this->getNamePlatform());
}
- actions.class.php
public function executeIndex(sfWebRequest $request)
{
$this->platforms = Doctrine_Core::getTable('platform')->findAll();
}
public function executeShow(sfWebRequest $request)
{
$this->platform = Doctrine_Core::getTable('platform')->find(array($request->getParameter('id')));
$this->games = $this->platform->getGames();
}
- indexSuccess.php
<?php slot('title')?>
<?php echo 'LLG: Platforms' ?>
<?php end_slot();?>
<h1>Platforms</h1>
<span class="little">Choose a platform for listing all the games belonging to it.</span>
<table>
<tbody>
<?php foreach ($platforms as $platform): ?>
<tr>
<td><a href="<?php echo url_for('platform_show_platform',$platform) ?>"><?php echo $platform->getNamePlatform() ?></a> (<?php echo $platform->getAcronyme()?>)</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<a href="<?php echo url_for('@homepage') ?>">Games</a>
<a href="<?php echo url_for('@genre') ?>">Genres</a>
- showSuccess.php
<?php slot('title') ?>
<?php echo sprintf('%s','LLG: '.$platform->getNamePlatform()) ?>
<?php end_slot(); ?>
<h1><?php echo $platform->getNamePlatform() ?></h1>
<?php if(sizeof($games)>0): ?>
<table>
<tbody>
<tr>
<th>Game</th>
<th>Developer</th>
<th>Publisher</th>
<th>Release Date</th>
<?php foreach($games as $game): ?>
<tr>
<td><a href="<?php echo url_for('game_show_game',$game) ?>"><?php echo $game->getNameGame()?></a></td>
<td><?php echo $game->getDeveloper() ?></td>
<td><?php echo $game->getPublisher() ?></td>
<td><?php echo $game->getReleaseDate() ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else:?>
<span>There are no games currently listed for this platform.<br>Return to:</span>
<?php endif;?>
<a href="<?php echo url_for('@homepage') ?>">Games</a>
<a href="<?php echo url_for('@genre') ?>">Genres</a>
<a href="<?php echo url_for('@platform')?>">Platforms</a>
- Liens dans la fiche du jeu
<tr>
<th>Platforms:</th>
<td><?php foreach ($platforms as $platform){
echo '<a href="'.url_for('platform_show_platform',$platform).'">'.$platform.'</a><br/>';} ?></td>
</tr>