Saturday, August 17, 2013

RE: bootstrap twitter typeahead , dont work for me in cakephp

But you need to define how to respond no?

 

As HTML, JSON am I wrong?

 

Set the data as a JSON reponse? You have to define it as a response in the correct format FOR THE js or html to act accordingly..

 

Dave Maharaj

Freelance Designer | Developer

www.movepixels.com  |  dave@movepixels.com  |  709.800.0852

 

From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf Of euromark
Sent: Friday, August 16, 2013 5:10 PM
To: cake-php@googlegroups.com
Subject: Re: bootstrap twitter typeahead , dont work for me in cakephp

 

Never create a new response object

there is already one available in your controller

 

just use 

 

    $this->response->body($content);

 

as documented



Am Freitag, 16. August 2013 19:16:32 UTC+2 schrieb cesar calvo:

I use this in my AppController

public function jsonResponse($array) {
        return new CakeResponse(array('body' => json_encode($array)));
    }

Then on a controller call jsonResponse


Note: if you are usin Security component on beforeFilter:

if ($this->request->is('ajax')) $this->Security->unlockedActions = array($this->request->action);

On Thursday, August 15, 2013 11:03:34 PM UTC-3, Renato Bigliazzi wrote:

Hi , I can not do the twitter bootstrap component typeahead work with cake. i use https://github.com/rudylee/cbunny , but dont work form me.

 

 

In my view

 

JS

 

<script type="text/javascript">

 $(document).ready(function(){        

            $('#itemdesc').typeahead({

    source: function (query, process) {

      return $.ajax({

        url:'<?php echo Router::url(array('controller'=>'Invoices','action'=>'localizaprodutos'));?>',

        type: 'get',

        data: {q: query},

        dataType: 'json',

        success: function (json) {

          return process(json);

        }

      });

    }

  });

});

</script>

 

HTML

<input type="text" name="itemdesc[]"  class="input-large" id="itemdesc" data-provide="typeahead"/>

 

 

and controller

 

public function localizaprodutos(){

                       

                        $this->autoRender = false;

        $this->RequestHandler->respondAs('json');

 

        // get the search term from URL

        $term = $this->request->query['q'];

        $users = $this->Invoice->Invoicedetail->Inventoryitem->find('all',array(

            'conditions' => array(

                'Inventoryitem.desc LIKE' => '%'.$term.'%'

            )

        ));

 

        // Format the result for select2

        $result = array();

        foreach($produtos as $key => $produto) {

            array_push($result, $produto['Inventoryitem']['desc']);

        }

        $produtos = $result;

        

        echo json_encode($produtos);

    }

 

 

Thanks

 

Renato

 

 

 

 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: