5

I am looking for examples on how to implement jquery's autocomplete via zend framework 2.

Based on my previous experiences with autocomplete using java and coldfusion, the http response must be only the JSON data. but Zend would normally attach a layout HTML (as defined by the module config). I was thinking of using an empty layout file (contents would be content; ?>) but I'm not sure if this is the correct (i.e. Zend way) of doing this.

I've been searching the net but can't find anything useful.

Can you please help with examples/links/etc? thanks

2
  • 2
    This might help -> akrabat.com/zend-framework-2/… Commented Jun 21, 2013 at 7:14
  • that's the way to go :) Commented Jun 21, 2013 at 8:34

1 Answer 1

0

To create the autocomplete, you need:

  1. Create a controller to respond in json receiving the parameter by get or post.

.

public function searchAction(){
// GET
$Params = $this->params ();
$count = $Params->fromQuery ( 'count', 10 ); 
$offset = $Params->fromQuery ( 'offset', 0 );
$search = $Params->fromQuery ( 'search', null );

// Mapper
$Search = TableMapper ();
$rs = $Search->search ( search, $count, $offset )); 

//I think good idea create an restful service if you have anothers requests

header('Content-Type: application/json');
echo \Zend\Json\Json::encode ( array (
        'status' => true,
        'data' => $rs,
) );
die (); }
  1. jQuery / Angle collecting the letters typed in the field.

    $("#input").keyup(function(event) {
    var stt = $(this).val();
    /**
    The search is route example, you need put correct url/route
    **/
    $.get( "/search", function( response ) {
        if(response.status == true){
            $( ".result" ).html( response );
        }
    });
    });
    
  2. html to show the response

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.