For JSON exchange I doing special module 'json' named.
Addition I create "config" folder for "json" module and create
"view.yml" whithout template.
My actions sample:

    public function executeNewChart(sfWebRequest $request) {
        $retData = array();
/*
only ajax request
*/
        if ($request->isXmlHttpRequest()) {
/* any manipulation data  */
            $this->getUser()->setAttribute('statYear', $request-
>getParameter('statChartType', 'p3') );
            $retData['statYear'] = $this->getUser()->getAttribute
('year', date('Y', time() ) );
            $retData['statView'] = $this->getUser()->getAttribute
('statView', 'toCommon');
            $retData['statTypeService'] = $this->getUser()-
>getAttribute('statTypeService', 'hosting');
            $retData['statChartType'] = $request->getParameter
('statChartType'); //$newReport->createStatData($this->getUser()-
>getAttribute('statTypeService'));
            $newReport = new statHarvester( $this->getUser()-
>getAttribute('statTypeService'), $request->getParameter('year'));
            $retData['newReport'] = '';
/* create JSON*/
            $retData = json_encode( $retData );
/* Prepare JSON data */
            $this->renderText( $retData );
        }
        // without template and RETURN
        return sfView::NONE;
    }

You remember, if use "dev" env - Symfony send add information, can
destroy JSON data - use "PROD" dev for testing and debug.

Sorry for my english, but I think what my understand.


On 1 фев, 12:57, Dong YANG <[email protected]> wrote:
> Hi Eno and Dejan,
>
>       Thanks for your replies, I found why I got always empty when calling
> json_encode in this method, in fact, the object returnd by
> $this->getRoute()->getObject() contains only protected and privated members,
> and json_encode treats only public members, so as result I got always '{}'.
>
>       Help this can help others.
>
>       Regards,
>
> JoJo
>
> 2010/1/29 Dejan Spasic <[email protected]>
>
> > If you use Doctrine try
>
> > json_encode($this->test->toArray());
>
> > On 28 Jan., 23:39, Eno <[email protected]> wrote:
> > > On Thu, 28 Jan 2010, Dong YANG wrote:
> > > > Hi everyone,
>
> > > >     I passed many hours for this strange thing, in fact I got a problem
> > when
> > > > using json_encode in symfony.
>
> > > >      In my front-end module, method executeIndex() as below:
>
> > > >   public function executeIndex(sfWebRequest $request)
> > > >   {
> > > >         $this->test = $this->getRoute()->getObject();
> > > >         // Call json_encode, but return '{}'
> > > >         $json = json_encode($this->test);
>
> > > >         // this simple test works
> > > >         $test = new stdClass();
> > > >         $test->id = new stdClass();
> > > >         var_dump(json_encode($test));
> > > >     }
>
> > > What happens if you do this?
>
> > > $test = $this->getRoute()->getObject();
> > > $json = json_encode($test);
> > > $this->test = $test;
>
> > > --
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "symfony users" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<symfony-users%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/symfony-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en.

Reply via email to