-- Fabrice Terrasson <[EMAIL PROTECTED]> wrote
(on Wednesday, 02 July 2008, 06:33 PM +0200):
> Matthew Weier O'Phinney a écrit :
> > Greets, all --
> >
> > I've committed the complete Zend_Dojo_Data implementation to the
> >
> Thank you !!!
>
> What's the handy way to get a proper json ?
>
> I tried a bit, in my controller:
>
> public function autocompleteAction() {
> $p= new Catalogue();
> $rows= $p->fetchAll();
>
> $f= new Zend_Dojo_Data();
> $f->setIdentifier('id');
> $f->addItems( $rows );
>
> $this->_helper->autoCompleteDojo( $f );
> //echo $f;
> }
Well, you've got one big problem here: autoCompleteDojo() isn't yet
wrapping Zend_Dojo_Data, so you'll get an inaccurate and invalid
structure as you show below.
For now, until I refactor autoCompleteDojo(), do this in your action
instead:
$this->_helper->viewRenderer->setNoRender(true);
$this->_helper->layout->disableLayout(true);
$response = $this->getResponse();
$response->setHeader('Content-Type', 'application/json')
->setBody($f->toJson());
I'll be refactoring autoCompleteDojo() in the coming week to allow
passing Zend_Dojo_Data objects, as well as to consume Zend_Dojo_Data to
create the payload when other types are passed to it.
> I m getting a well formated json file but complicated :
> {"identifier":"name",
> "items": [{
> "label": {"id":"1","produit":"pomme"},
> "name": {"id":"1","produit":"pomme"}
> },{
> "label": {"id":"2","produit":"orange"},
> "name": {"id":"2","produit":"orange"}
> }]}
>
> I'd prefer and "dojo.data.ItemFileReadStore" too, a simpler json like :
> {"identifier": "name",
> "items": [{
> "label":"pomme",
> "name":"pomme"
> },{
> "label":"orange",
> "name":"orange"}
> }]}
>
> fyi, this is the schema SQL :
> CREATE TABLE `catalogue` (
> `id` int(11) NOT NULL auto_increment,
> `produit` varchar(100) NOT NULL,
> PRIMARY KEY (`id`) );
>
> FT.
>
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend Framework | http://framework.zend.com/