使用 Zend 框架进行标记

发布于 2024-08-10 11:26:04 字数 1210 浏览 9 评论 0原文

我正在尝试创建与下面相同的解决方案,但使用简单的 MySQL 查询(而不是下面在代码中实现单词/标签的静态版本)。 MySQL 表的名称是“tags”,它有 2 列“id”和“id”。 “标签”。

不幸的是我是初学者,我无法解决这个问题。有人可以帮助我吗?

/* Zend_Tag_Item version*/

$list = new Zend_Tag_ItemList();

$list[] = new Zend_Tag_Item(array('title' => 'Code', 'weight' => 50));
$list[] = new Zend_Tag_Item(array('title' => 'Zend Framework', 'weight' => 1));
$list[] = new Zend_Tag_Item(array('title' => 'PHP', 'weight' => 5));

$list->spreadWeightValues(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));

foreach ($list as $item) {
    $this->view->tagtitle = $item->getTitle();
    $this->view->tagweight = $item->getParam('weightValue');
}


/* Zend_Tag_Cloud version*/

$cloud = new Zend_Tag_Cloud(array(
    'tags' => array(
        array('title' => 'Code', 'weight' => 50,
              'params' => array('url' => '/tag/code')),
        array('title' => 'Zend Framework', 'weight' => 1,
              'params' => array('url' => '/tag/zend-framework')),
        array('title' => 'PHP', 'weight' => 5,
              'params' => array('url' => '/tag/php')),
    )
));

$formdata->pagecontent->tagging = $cloud;

I'm trying to create the same solutions as below, but using a simple MySQL query (instead of the static version used below where the words/tags are implemented in the code). The name of the MySQL table is "tags" and it has 2 columns "id" & "tag".

Unfortunately I'm a beginner and I wasn't able to solve this. Can someone help me?

/* Zend_Tag_Item version*/

$list = new Zend_Tag_ItemList();

$list[] = new Zend_Tag_Item(array('title' => 'Code', 'weight' => 50));
$list[] = new Zend_Tag_Item(array('title' => 'Zend Framework', 'weight' => 1));
$list[] = new Zend_Tag_Item(array('title' => 'PHP', 'weight' => 5));

$list->spreadWeightValues(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));

foreach ($list as $item) {
    $this->view->tagtitle = $item->getTitle();
    $this->view->tagweight = $item->getParam('weightValue');
}


/* Zend_Tag_Cloud version*/

$cloud = new Zend_Tag_Cloud(array(
    'tags' => array(
        array('title' => 'Code', 'weight' => 50,
              'params' => array('url' => '/tag/code')),
        array('title' => 'Zend Framework', 'weight' => 1,
              'params' => array('url' => '/tag/zend-framework')),
        array('title' => 'PHP', 'weight' => 5,
              'params' => array('url' => '/tag/php')),
    )
));

$formdata->pagecontent->tagging = $cloud;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜嗑 2024-08-17 11:26:05

您可以在实现 MySQL 表的 DbTable 模型上执行 fetchAll,然后循环并添加项目,或者创建数组,例如:

$tags = array();
foreach($TagTable->fetchAdd() as $tag) {
     $tags[] = array('title' => $tag['tag'], 'weight' => $tag['weight']);
}

$cloud = new Zend_Tag_Cloud(array('tags' => $tags));

You could do a fetchAll on a DbTable model that implements your MySQL table, and then just loop and add the items, or create the array, for example:

$tags = array();
foreach($TagTable->fetchAdd() as $tag) {
     $tags[] = array('title' => $tag['tag'], 'weight' => $tag['weight']);
}

$cloud = new Zend_Tag_Cloud(array('tags' => $tags));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文