I’ve been trying to figure this out for a few days now. Could someone more experienced that I take a look and tell me what I’m doing wrong.
This is built in symfony 1.4, with the help of sfProtoculousPlugin for input_auto_complete_tag.
My template:
<?php echo input_auto_complete_tag(
'tag', /*id_of_field*/
'', /*default_value_of_field*/
'tag/autocomplete', /*url_to_ajax_script*/
array('autocomplete' => 'off'), /*array_with_extra_tag_attributes*/
array('use_style' => 'true') /*array_with_options*/
) ?>
<input type="submit" name="submit" value="Tag me!" />
...
</form>
Added to the top of my routing.yml:
tag_autocomplete:
url: /tag_autocomplete
param: { module: tag, action: autocomplete }
Created templates/autocompleteSuccess.php:
<ul>
<?php foreach ($tags as $tag): ?>
<li><?php echo $tag ?></li>
<?php endforeach; ?>
</ul>
Added this action to the modules/tag/actions/action.class.php file:
public function executeAutocomplete(sfWebRequest $request)
{
$this->tags = QuestionTag::getTagsForUserLike(
$this->getUser()->getGuardUser()->getId(),
$this->getRequestParameter('tag'),
10
);
}
Added this method to the QuestionTag.class.php file:
public static function getTagsForUserLike($user_id, $tag, $max = 10)
{
$tags = Doctrine_Query::create()
->select('qt.tag')
->from('QuestionTag qt')
->where('qt.user_id = ?', $user_id)
->andWhere("qt.tag LIKE '%".$tag."%'")
->orderBy('qt.tag')
->limit($max)
->fetchArray();
return $tags;
}
Here is the generated js code:
//<![CDATA[
new Ajax.Autocompleter('tag', 'tag_auto_complete', '/frontend_dev.php/tag_autocomplete', {});
//]]>
In my Firebug console, I get the following error:
Ajax is not defined
[Break On This Error]
...ax.Autocompleter('tag', 'tag_auto_complete', '/frontend_dev.php/tag_autocomplete...
I tried the following command, that supposedly copies the ‘assets’ (js scripts) to my /web folder. It seems to have worked for some, but not for me.
./symfony plugin:publish-assets sfProtoculousPlugin
I feel like I’m almost there. Any help would be greatly appreciated. Many thanks in advance.
Update 1
In my /web/sfProtoculousPlugin folder I have:
css /
input_auto_complete_tag.css
js/
builder.js
controls.js
dragdrop.js
effects.js
index.html
prototype.js
scriptaculous.js
slider.js
sound.js
unittest.js
Also, I don’t see a <script> tag with prototype.js inside.
SOLVED
Added this to the app settings.yml:
all:
.settings:
prototype_web_dir: /sfProtoculousPlugin
and this to the app view.yml:
javascripts: [%SF_PROTOTYPE_WEB_DIR%/js/prototype, %SF_PROTOTYPE_WEB_DIR%/js/scriptaculous]
Then I ran ./symfony cc and refreshed the page. It now works perfectly as I intended. Thanks j0k for your help.
Added this to the top of my template:
Added this to the app
settings.yml:Added this to the app
view.yml:Then I ran
./symfony ccand refreshed the page. It now works perfectly as I intended. Thanks j0k for your help.