使用 Zend 框架进行标记
我正在尝试创建与下面相同的解决方案,但使用简单的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在实现 MySQL 表的 DbTable 模型上执行 fetchAll,然后循环并添加项目,或者创建数组,例如:
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: