Bonjour,
Voici un debug de ma page accueil
array(
'posts' => array(
(int) 0 => array(
'Post' => array(
'id' => '6',
'name' => 'Mon premier article',
'slug' => 'mon-premier-article',
'content' => '<p>Lorem ipsum</p>',
'type' => 'post',
'online' => '1',
'category_id' => '1',
'user_id' => '1'
'media_id' => '14',
'thumb' => 'articles/2012/06/prga_velo_6_i.jpg',
'thumbf' => 'articles/2012/06/prga_velo_6_i_%dx%d.jpg',
'link' => array(
'controller' => 'posts',
'action' => 'show',
'id' => '6',
'slug' => 'mon-premier-article'
)
),
'Category' => array(
'id' => '1',
'name' => 'Vélo',
'slug' => 'velo',
'icon' => '',
'post_count' => '1',
'link' => array(
'controller' => 'posts',
'action' => 'category',
'slug' => 'velo'
)
),
'Thumb' => array(
'id' => '14',
'ref' => 'Post',
'ref_id' => '6',
'file' => 'articles/2012/06/prga_velo_6_i.jpg',
'position' => '0',
'filef' => 'articles/2012/06/prga_velo_6_i_%dx%d.jpg'
)
)
)
)
Voici le foreach de ma vue :
<?php foreach ($posts as $k => $v): $v = current($v); ?>
<a href="<?php echo $this->Html->url($v'link']); ?>">
<div class="grid3">
<?php echo $this->Html->image(sprintf($v'thumbf'],220,113)); ?>
<h3><?php echo substr($v'name'],0,20); ?></h3>
</div>
</a>
<?php endforeach; ?>
Voici mon controller :
$this->loadModel('Post');
$this->Post->contain('Thumb','Category');
$d'posts'] = $this->Post->find('all',array(
'conditions' => array('type'=>'post','online'=>1),
'order' => 'Post.created DESC',
'limit' => 4
));
$this->set($d);
Comment faites vous pour récupérer dans le foreach le nom de la catégorie associée à mon article, par exemple içi Vélo.
Merci