JQuery UI Autocomplete with Zend Framework

前端 未结 1 1238
无人共我
无人共我 2021-01-01 04:17

I was wondering about how to add the autocomplete JQuery UI widget to a form I\'m developing in the Zend Framework without using ZendX. The folders for the website are set u

相关标签:
1条回答
  • 2021-01-01 04:37

    this should work for you:

    // js stuff
    $( "input#autocomplete" ).autocomplete({
        source: "http://localhost/application/index/autocomplete"
    });
    
    
    //IndexController.php
    
    /**
     * Return AutoComplete stuff
     */
    public function autocompleteAction()
    {
        // disable view and layout, we want some fanzy json returned
        $this->_helper->layout()->disableLayout(); 
        $this->_helper->viewRenderer->setNoRender(true);
    
        $values = array('best', 'buy');
        $valuesJson = Zend_Json::encode($values);
        echo $valuesJson;
    }
    

    You could altough pass the BaseUrl to your Script (instead of using fullpath)

    //layout.phtml
    <script type="text/javascript">
    var baseUrl = "<?= $this->baseUrl(); ?>";
    </script>
    

    So you could do:

    source: baseUrl + "/index/autocomplete"
    
    0 讨论(0)
提交回复
热议问题