Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cakephp2:如何在Cakephp2中显示链接内的内容数量_Php_Cakephp 2.0_Tag Cloud - Fatal编程技术网

Cakephp2:如何在Cakephp2中显示链接内的内容数量

Cakephp2:如何在Cakephp2中显示链接内的内容数量,php,cakephp-2.0,tag-cloud,Php,Cakephp 2.0,Tag Cloud,我是cakephp2的新手,我是来寻找解决方案的。 问题是我在cakephp2中有这样一个链接列表 但问题是我想显示如下示例所示的内容数量 对于像我这样的业余爱好者来说,这有点太难了。我不知道如何实现链接中的列表或内容的数量,也不知道如何称呼它。如果像你这样的专业人士能帮助我,那就太好了! 对不起,我的英语很差。您可能需要这样的HABTM设置: Class Tag extends AppModel { public $name = 'Tag'; public $hasAn

我是cakephp2的新手,我是来寻找解决方案的。 问题是我在cakephp2中有这样一个链接列表

但问题是我想显示如下示例所示的内容数量

对于像我这样的业余爱好者来说,这有点太难了。我不知道如何实现链接中的列表或内容的数量,也不知道如何称呼它。如果像你这样的专业人士能帮助我,那就太好了!
对不起,我的英语很差。

您可能需要这样的HABTM设置:

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',
            )
        );
}
将以下内容添加到AppModel中,您将永远不会回头:

class AppModel extends Model {

    public $actsAs = array('Containable');
}
在控制器中:

$results = $this->Tag->find('all, array(
    'contain' => array('Article)
    ));

$this->set('results', $results);
鉴于:

<ul class="tags">

<?php foreach ($results as $data) : ?>
<li class="tag"><?php 

echo $this->Html->link($data['Tag']['name'] . ' (' . count($data['Article']) . ')', 
    '/tag/' . $data['Tag']['slug'],
    array('title' => 'View articles for ' . $data['Tag']['name'], 'escape' => false));

?></li>
<?php endforeach; ?>

</ul>

希望这能有所帮助。

所以这里不是人们为你做所有工作的地方,而是帮助你解决具体问题的地方。因此,如果您需要帮助,那么您应该指定您所面临的实际编程相关问题。抱歉。作为一名初中生,我认为最好先问有经验的程序员,因为我已经厌倦了把制作垃圾网站作为一种嗜好。但我很感激帮助我的人。