Since version 4.6.0, Tags (topics) and Hashtags can be used at the same time. So, we prepare this tutorial to help you can integrate your app with both of them.
Note: we will use the app the To Do List app as an example for this tutorial.
h2. Tags
Scope
: only in the app.Related Setting
: Enable Tags (tag.enable_tag_support) - Enable this option if you wish to allow tags on the site to create topics for the item being added.
...
Code Block |
---|
| actionscript3 |
---|
| actionscript3 |
---|
|
{if Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_tag_support')}
{module name='tag.add' sType='todo'}
{/if}
|
In controller of edit Edit page, we need to get get tags list of editing edited item
Code Block |
---|
|
if (Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_tag_support')) {
$todo['tag_list'] = Phpfox::getService('tag')->getForEdit('todo', $id);
}
|
- Add/Update tags list when addadding/edit editing item
Code Block |
---|
|
// Add this php code in service add
if (Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_tag_support')) {
if (isset($aVals['tag_list']) && ((is_array($aVals['tag_list']) && count($aVals['tag_list'])) || (!empty($aVals['tag_list'])))) {
Phpfox::getService('tag.process')->add('todo', $iItemId, Phpfox::getUserId(), $aVals['tag_list']);
}
}
|
Code Block |
---|
|
// Add this php code in service update
if (Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_tag_support')) {
if (Phpfox::isModule('tag') && isset($aVals['tag_list']) && !empty($aVals['tag_list'])) {
Phpfox::getService('tag.process')->update('todo', $aVals['task_id'], $aVals['user_id'], $aVals['tag_list']);
}
}
|
- Display tags lists of item in detail Detail page
Code Block |
---|
|
// Add this php code in controller of detail page to get tags list
if (Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_tag_support')) {
$aTags = Phpfox::getService('tag')->getTagsById('todo',
$id);
if (isset($aTags[$id])) {
$aItem['tag_list'] = $aTags[$id];
}
}
|
Code Block |
---|
| actionscript3 |
---|
| actionscript3 |
---|
|
<!-- Add this code in view template -->
{if isset($aItem.tag_list)}
{module name='tag.item' sType='todo' sTags=$aItem.tag_list iItemId=$aItem.task_id iUserId=$aItem.user_id sMicroKeywords='keywords'}
{/if}
|
...
- To support search by tags, we have to add a callback name:
getTagLink
. This callback will return link to search item by tag of the app. Example:
Code Block |
---|
|
/**
* @return string
*/
public function getTagLink()
{
return Phpfox_Url::instance()->makeUrl('to-do-list.tag');
}
|
...
How to use?
- Add/Update hashtags when addadding/edit editing item.
Code Block |
---|
|
// Add this php code in service add
if (Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_hashtag_support')) {
Phpfox::getService('tag.process')->add('todo', $iItemId, Phpfox::getUserId(), $aVals['description'], true);
}
|
Code Block |
---|
|
// Add this php code in service update
if (Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_hashtag_support')) {
Phpfox::getService('tag.process')->update('todo', $aVals['task_id'], $aTodo['user_id'], $aVals['description'], true);
}
|
- To show hashtags on your detail page, you need to process your content with template built-in function
parse
:
Code Block |
---|
| actionscript3 |
---|
| actionscript3 |
---|
|
{$aItem.description|parse}
|
...