2009-11-06 95 views
0

我試圖創建與以下相同的解決方案,但使用簡單的MySQL查詢(而不是以下用於代碼中實現的單詞/標籤的靜態版本)。 MySQL表的名字是「tags」,它有2列「id」&「tag」。使用Zend框架標記

不幸的是我是初學者,我無法解決這個問題。有人能幫我嗎?

/* 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; 

回答

0

你可以做一個使用fetchall上實現你的MySQL表一個DbTable模型,然後只需循環,並添加項目,或創建一個數組,例如:

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

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

ID可能不是正確的方式來實現重量:)更好的做一個查詢與標籤和計數(標籤)作爲重量 – 2009-11-07 12:05:10

+0

我會upvote,但'重量'的東西應該編輯! – RageZ 2009-11-10 08:40:12

+0

我認爲這取決於用戶,她說她只有id&tag :) – Chris 2009-11-10 16:40:04