Since version 4.6.0, Tags (topics) and Hashtags can be used at the same time. So, we prepare this tutorial to integrate your app with both of them.
Note: we will use the To Do List app as an example for this tutorial.
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.
How to use?
- Render the field to add
Tags
for your item in add/edit form
Code Block |
---|
| actionscript3 |
---|
| actionscript3 |
---|
|
{if Phpfox::isModule('tag') && Phpfox::getParam('tag.enable_tag_support')}
{module name='tag.add' sType='todo'}
{/if}
|
Image Added
In controller of Edit page, we need to get tags list of 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 adding/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 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}
|
Image Added
- 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');
}
|
- We also have to implement a page for browsing items by tag. For more detail, please check the source code of the sample app To Do List
Image Added
Hashtags
Scope
: using for entire site. You can support to add hashtags in description of your items.Related Setting
: Enable Hashtags (tag.enable_hashtag_support) - Enable this option if you wish to allow hashtags on the site to create topics for the item being added.
How to use?
- Add/Update hashtags when adding/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}
|
Image Added