Hi all
I try to link two tables, Blogs and Membres, with an Blogsmembres intersection table :
Here are the classes I use :
PHP Code:
class Blogs extends Zend_Db_Table_Abstract
{
protected $_name = 'blogs';
protected $_primary = 'id';
protected $_dependentTables = array('Blogsmembres');
}
PHP Code:
class Membres extends Zend_Db_Table_Abstract
{
protected $_name = 'membres';
protected $_primary = 'id';
protected $_dependentTables = array('Blogsmembres');
}
PHP Code:
class Blogsmembres extends Zend_Db_Table_Abstract
{
protected $_name = 'blogs_membres';
protected $_primary = array('membre_id','blog_id');
protected $_referenceMap = array(
'Membres' => array(
'columns' => 'membre_id',
'refTableClass' => 'Membres',
'refColumns' => 'id'
),
'Blogs' => array(
'columns' => 'blog_id',
'refTableClass' => 'Blogs',
'refColumns' => 'id'
));
}
Here is the controller I use :
PHP Code:
public function indexAction() {
$this->view->titre= "Accueil";
//Module Blogs
$blog = new Blogs();
$selection=$blog->select()->setIntegrityCheck(false);
$selection->from($blog);
$selection->joinLeft("blogs_membres","blogs.id=blogs_membres.blog_id");
$selection->joinLeft("membres","membres.id=blogs_membres.blog_id");
$selection->group('blogs.id');
$this->view->sites=$blog->fetchAll($selection);
}
Here is the view I use :
HTML Code:
<table border="1" cellspacing="0" cellpadding="2">
<tr><td>Nom</td><td>Auteur</td><td>Actions</td>
<?php foreach($this->sites as $site) :
$site_authors=$site->findMembresViaBlogsmembres();
foreach($site_authors as $site_author)
{
$authors[$site_author->membre_id]=$site_author->pseudo;
}
?>
<tr>
<td><a href="<?php echo $this->escape($site->url_site);?>"><?php echo $this->escape($site->titre);?></a></td>
<td><?php echo implode(",",$authors);?></td>
<td>
<a href="<?php echo $this->baseUrl; ?>/blogs/modifier/id/<?php
echo $site->id;?>">Modifier</a>
<a href="<?php echo $this->baseUrl; ?>/blogs/supprimer/id/<?php
echo $membre->id;?>">Supprimer</a>
</td>
</tr>
<?php endforeach; ?>
</table>
Is existing any dirty-less method than that ? Am I forced to use some PHP code in my view ?