Hi guys.
I am facing a small problem in my project. I have tried a lot but its not solved.
I am using the suggested tag option in my project.
I have set the suggettag action and the normalize tag settings in my model and also set the view. Now when I enter the list of tags in the tag field then as it is saved in the tag table with frequency update etc.
But next time when wanna enter the tag in the tag field of the form then the pre entered or suggested tags are not displaying (as in the blog example of post creation).
I have share the code here plz have a look on it and tell me the answer.
[Post model code]
public function rules() {
return array(
array('post_type, category_id, title, description, status', 'required'),
array('tags', 'safe'),
array('tags', 'match', 'pattern' => '/^[\w\s,]+$/', 'message' => 'Tags can only contain word characters.'),
array('tags', 'normalizeTags'),
);
}
public function getTagLinks() {
$links = array();
foreach (Tag::string2array($this->tags) as $tag)
$links[] = CHtml::link(CHtml::encode($tag), array('post/index', 'tags' => $tags));
return $links;
}
public function normalizeTags($attribute, $params) {
$this->tags = Tag::array2string(array_unique(Tag::string2array($this->tags)));
}
protected function afterFind() {
parent::afterFind();
$this->_oldTags = $this->tags;
}
protected function afterSave() {
parent::afterSave();
Tag::model()->updateFrequency($this->_oldTags, $this->tags);
}
[Post controller action]
public function actionSuggestTags() {
if (isset($_GET['q']) && ($keyword = trim($_GET['q'])) !== '') {
$tags = Tag::model()->suggestTags($keyword);
if ($tags !== array())
echo implode("\n", $tags);
}
}
[and here is the post _form code]
<?php echo $form->label($model, 'tags', array('class' => 'control-label')); ?>
<div class="controls">
<?php
$this->widget('CAutoComplete', array(
'model' => $model,
'attribute' => 'tags',
'url' => array('suggestTags'),
'multiple' => true,
'htmlOptions' => array('size' => 50, 'class' => ''),
));
?>
<p class="help-block">Enter tags separated by commas</p>
</div>
thanks in advance.