2009年8月26日星期三

RE: [fw-mvc] Fetch data to Json conversion issue

Hello !


Well no it does not work,
dijit.form.ComboBox does not getting filled. $data->toArray() converts data to array but not in the format it needs. It needs format like below :

 

echo "{identifier:'name',items: [

      {name:'Champaign', label:'Champaign'},

      {name:'Chicago', label:'Chicago'},

      {name:'Naperville', label:'Naperville'},

      {name:'Wheaton', label:'Alaska'}]}";     

}

 

This is what combo box needs to populate.

 

In a simple application with dojo.combobox but in Zend, I did as below and it worked.

 

$arr = array (

   identifier=>'name',

   items=>array(

      array('name'=>'Anytown', 'label'=>'Anytown'),

      array('name'=>'Second', 'label'=>'Second')

   )

);

echo json_encode($arr);

 

but now the array is dynamic so how to generate this style array.

 

I also tried giving

            $dojoData= new Zend_Dojo_Data('taskhead_cd',$data, 'taskhead_cd'); and passing $dojodata to

            $this->_helper->json($dojodataarray('enableJsonExprFinder' => true)); 

 

But that also is not working and I saw in debugger this also does not generate output as mentioned above so may be combobox not getting filled.

 

Please help on this, what to give now.

 

Thanks in Advance !

 

Naimesh

 

From: oreales [mailto:oreales@gmail.com]
Sent: Tuesday, August 25, 2009 8:38 PM
To: Naimesh.Trivedi (Gmail)
Cc: fw-general@lists.zend.com; fw-mvc@lists.zend.com
Subject: Re: [fw-mvc] Fetch data to Json conversion issue

 

fetchAll will return an Zend_Db_Table_Rowset_Abstract object. This object, store "data" in a "protected" propertie ($_data), so, json_encoding an object will encode the "PUBLIC" properties of an object. I think you can use toArray() method  to obtain the data as an array. Try this:

 

 

public function gettaskAction()

      {

            $taskhead new Taskhead();

            $data$taskhead->fetchAll();

            $arr array (identifier=>'name',

                  items=>array(

                  array('name'=>'Bidding''label'=>'Bidding'),

                  array('name'=>'Response-proposal    ''label'=>'Response-proposal')

               )

            );

            $this->_helper->json($data->toArray()array('enableJsonExprFinder' => true));          

      }

 

Zend_Db_Table_Rowset_Abstrac

El 25/08/2009, a las 14:41, Naimesh.Trivedi (Gmail) escribió:



Dear Sir,

 

 

Hello ! Well I am calling ajax request from my javascript function which in turn is called from dojo.combobox onChange event. I want to return Json output to this javascript from my action. It works well on hard coded array $arr but does not work with $data which has actual dynamic table data.

 

 

      public function gettaskAction()

      {

            $taskhead = new Taskhead();

            $data= $taskhead->fetchAll();

            $arr = array (identifier=>'name',

                  items=>array(

                  array('name'=>'Bidding', 'label'=>'Bidding'),

                  array('name'=>'Response-proposal    ', 'label'=>'Response-proposal')

               )

            );

            $this->_helper->json($data, array('enableJsonExprFinder' => true));          

      }

 

If I put above $arr in place of $data in json call, it works well and populate my comboxbox but putting $data it does not work, might be not proper json format is converted.

 

Please guide me on this.

 

Thanks in Advance !

 

Naimesh

 

 

 

没有评论: