Friday, 15 February 2013

php - Cakephp2: How to display number of contents within the link in the cakephp2 -



php - Cakephp2: How to display number of contents within the link in the cakephp2 -

i'm new cakephp2 , came find solution. problem have list of links in cakephp2

but problem want display number of contents sample below

for amature me bit difficult.i not know how implement number of lists or contents in link or how phone call .it great if pros can help me out! sorry poor english.

you need habtm setup this:

class tag extends appmodel { public $name = 'tag'; public $hasandbelongstomany = array( 'article' => array( 'classname' => 'article', 'jointable' => 'articles_tags', 'foreignkey' => 'tag_id', 'associationforeignkey' => 'article_id', ) ); } class articlestag extends appmodel { public $name = 'articlestag'; } class article extends appmodel { public $name = 'article'; public $hasandbelongstomany = array( 'tag' => array( 'classname' => 'tag', 'jointable' => 'articles_tags', 'foreignkey' => 'article_id', 'associationforeignkey' => 'tag_id', ) ); }

add next appmodel, never back:

class appmodel extends model { public $actsas = array('containable'); }

in controller:

$results = $this->tag->find('all, array( 'contain' => array('article) )); $this->set('results', $results);

in view:

<ul class="tags"> <?php foreach ($results $data) : ?> <li class="tag"><?php echo $this->html->link($data['tag']['name'] . ' (' . count($data['article']) . ')', '/tag/' . $data['tag']['slug'], array('title' => 'view articles ' . $data['tag']['name'], 'escape' => false)); ?></li> <?php endforeach; ?> </ul>

hope helps.

php cakephp-2.0 tag-cloud

No comments:

Post a Comment