views:

97

answers:

1

I am trying to implement this tutorial in my application. I have managed to make it work until the point where I had to modify the view controller and add the link to the .ajax.html file.

My code so far:

 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;
        }
        }

The add-recipe.ajax.phtml file:

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

The view file 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" />

For some strange reason if i replace $('#username').autocompleteArray('http://bucatarie/menu/add-recipe/format/html'); with $('#username').autocompleteArray(['Jack', 'John', 'Jason', 'Jeremy', 'jimmy', 'jean']); it works perfect. I can't seem to understand what the problem is.

A: 

Try this:

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);

    }
}

This should work.

What's the purpose of the code bellow?

$recipeForm = new Application_Form_Recipe();
$recipeForm->setMethod('post');
$recipeForm->setAction('/menu/add-recipe');
$this->view->recipeForm = $recipeForm;
Keyne
Why down vote? This code should work. The problem like was said in the comments, is with the output returned by the php. I really didn't understand...
Keyne
i have solved it using ZendX AutoComplete.