jquery自动完成和zend框架的问题

时间:2010-08-16 18:07:20

标签: php javascript jquery zend-framework

我正在尝试在我的应用程序中实现this教程。我已设法使其工作,直到我必须修改视图控制器并将链接添加到.ajax.html文件。

到目前为止我的代码:

 class MenuController extends Zend_Controller_Action {

        public function init() {
            $this->_helper->ajaxContext()->addActionContext('addRecipe', 'html')->initContext();
            parent::init();
     }

              public function addRecipeAction() {
            if ($this->_helper->ajaxContext()->getCurrentContext()) {
                $this->view->words = array('leon', 'lionel', 'Lenny', 'Linda', 'Lindy');
            }

            $recipeForm = new Application_Form_Recipe();
            $recipeForm->setMethod('post');
            $recipeForm->setAction('/menu/add-recipe');
            $this->view->recipeForm = $recipeForm;
        }
        }

add-recipe.ajax.phtml文件:

<?php
foreach ($this->words as $word) {
    echo "{$word}\n";
}
?>

视图文件add-recipe.phtml

<?php

echo $this->headLink()->appendStylesheet('/js/jquery/css/jquery.autocomplete.css');
$this->jQuery()->enable();
$this->jQuery()->addJavascriptFile('/js/jquery/js/jquery.autocomplete.js');

?>
<script type="text/javascript">
    $(document).ready(function(){
            $('#username').autocompleteArray('http://bucatarie/menu/add-recipe/format/html');
    });
</script>


<input type="text" name="username" id="username" />

出于某种奇怪的原因,如果我用$('#username').autocompleteArray('http://bucatarie/menu/add-recipe/format/html');替换$('#username').autocompleteArray(['Jack', 'John', 'Jason', 'Jeremy', 'jimmy', 'jean']);,它就会完美无缺。我似乎无法理解问题所在。

1 个答案:

答案 0 :(得分:-1)

试试这个:

class MenuController extends Zend_Controller_Action {

    public function addRecipeAction() {

        $words = array('leon', 'lionel', 'Lenny', 'Linda', 'Lindy');

        foreach($words as $w) echo "$w\n";

        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

    }
}

这应该有用。

下面代码的目的是什么?

$recipeForm = new Application_Form_Recipe();
$recipeForm->setMethod('post');
$recipeForm->setAction('/menu/add-recipe');
$this->view->recipeForm = $recipeForm;