使用Zend Framework进行标记

时间:2009-11-06 14:26:30

标签: php zend-framework tagging zend-tag

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

1 个答案:

答案 0 :(得分:0)

您可以在实现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));