Saturday, January 31, 2009

Re: Accessing $javascript->object() results

I found one link finally on google, but it doesn't provide enough
detail. Seems he uses jQuery, but I don't know anything about jQuery.

http://debuggable.com/posts/passing-controller-variables-to-your-javascript:48b4f0c6-c718-47b2-bca1-05794834cda3

Here it is for reference. I still would like to know a more basic
method, either with plain javascript or prototype as that is what cake
uses.

On Jan 29, 4:26 pm, Pyrite <thelette...@gmail.com> wrote:
> I have found many blogs talking about how you can have your controller
> send to your view the results of some:
>
> $data = $this->MyModel->find('all', array('some params'));
> $this->set('data', $data);
>
> And then in your view:
>
> echo $javascript->object($data);
>
> Now, how the heck in the view using Javascript do I access the results
> of that method. I know it outputs a JSON string, and I figured I would
> probably want to output it in a javascript var in my layout like:
>
> <script type="text/javascript">
> var myJsonObject = <?php echo $javascript->object($data); ?>;
> </script>
>
> So how (using Javascript) in my view do I access the data in
> myJsonObject???
>
>  Like I want to populate some select dropdowns with it. Just not sure
> of the syntax to access myJsonObject.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: