Re: Rendering an element with Jquery

2011-09-14 Thread Thomas Ploch
The easiest way would be an AJAX action that renders the element with 
the given POST data. The you can just use the rendered HTML and inject 
it into the DOM.


Kind regards
Thomas

Am 14.09.2011 16:55, schrieb 8vius:

Hey all, got a little problem here. I wanna do something similar to
what twitter does when you post a new tweet, that it automatically
adds itself to the stream. I have made an element for this, the
element receives my model data and sets it up properly but I'm not
sure how to pass in the data from Jquery (I receive a JSON object). So
what are my options here? How can I accomplish this?



--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.



To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Rendering an element with Jquery

2011-09-14 Thread 8vius
Can you be a little more explicit? I have my ajax action set up that
will return a json encoded array. How can I get the html for the
element from my controller? Maybe some example code? I'm a bit of a
noob with this in general. Thank you.

On Sep 14, 11:05 am, Thomas Ploch profipl...@googlemail.com wrote:
 The easiest way would be an AJAX action that renders the element with
 the given POST data. The you can just use the rendered HTML and inject
 it into the DOM.

 Kind regards
 Thomas

 Am 14.09.2011 16:55, schrieb 8vius:







  Hey all, got a little problem here. I wanna do something similar to
  what twitter does when you post a new tweet, that it automatically
  adds itself to the stream. I have made an element for this, the
  element receives my model data and sets it up properly but I'm not
  sure how to pass in the data from Jquery (I receive a JSON object). So
  what are my options here? How can I accomplish this?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Rendering an element with Jquery

2011-09-14 Thread Thomas Ploch

As an addition, check out http://book.cakephp.org/view/980/render

Am 14.09.2011 17:14, schrieb 8vius:

Can you be a little more explicit? I have my ajax action set up that
will return a json encoded array. How can I get the html for the
element from my controller? Maybe some example code? I'm a bit of a
noob with this in general. Thank you.

On Sep 14, 11:05 am, Thomas Plochprofipl...@googlemail.com  wrote:

The easiest way would be an AJAX action that renders the element with
the given POST data. The you can just use the rendered HTML and inject
it into the DOM.

Kind regards
Thomas

Am 14.09.2011 16:55, schrieb 8vius:








Hey all, got a little problem here. I wanna do something similar to
what twitter does when you post a new tweet, that it automatically
adds itself to the stream. I have made an element for this, the
element receives my model data and sets it up properly but I'm not
sure how to pass in the data from Jquery (I receive a JSON object). So
what are my options here? How can I accomplish this?




--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.



To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Rendering an element with Jquery

2011-09-14 Thread 8vius
hmmm I don't use the request handler to do my ajax requests, I just
echo out the response, would that work ? doing echo $this-render()?

On Sep 14, 11:36 am, Thomas Ploch profipl...@googlemail.com wrote:
 As an addition, check outhttp://book.cakephp.org/view/980/render

 Am 14.09.2011 17:14, schrieb 8vius:







  Can you be a little more explicit? I have my ajax action set up that
  will return a json encoded array. How can I get the html for the
  element from my controller? Maybe some example code? I'm a bit of a
  noob with this in general. Thank you.

  On Sep 14, 11:05 am, Thomas Plochprofipl...@googlemail.com  wrote:
  The easiest way would be an AJAX action that renders the element with
  the given POST data. The you can just use the rendered HTML and inject
  it into the DOM.

  Kind regards
  Thomas

  Am 14.09.2011 16:55, schrieb 8vius:

  Hey all, got a little problem here. I wanna do something similar to
  what twitter does when you post a new tweet, that it automatically
  adds itself to the stream. I have made an element for this, the
  element receives my model data and sets it up properly but I'm not
  sure how to pass in the data from Jquery (I receive a JSON object). So
  what are my options here? How can I accomplish this?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Rendering an element with Jquery

2011-09-14 Thread Thomas Ploch
The RequestHandler Component is not doing any requests, it just verifies 
that the current request indeed is an AJAX request, so you can check in 
an action and i.e. render an element with an AJAX layout instead of 
rendering the whole view. You can of course generate the HTML with 
javascript using the returned JSON object ( 
http://api.jquery.com/jQuery.template ). But in my oppinion it is way 
easier to do the data handling in the action, and just render the 
element's HTML with $this-render() and use that in the success callback 
of the jQuery $.post method, appending the rendered HTML into a DOM node.


Am 14.09.2011 17:51, schrieb 8vius:

hmmm I don't use the request handler to do my ajax requests, I just
echo out the response, would that work ? doing echo $this-render()?

On Sep 14, 11:36 am, Thomas Plochprofipl...@googlemail.com  wrote:

As an addition, check outhttp://book.cakephp.org/view/980/render

Am 14.09.2011 17:14, schrieb 8vius:








Can you be a little more explicit? I have my ajax action set up that
will return a json encoded array. How can I get the html for the
element from my controller? Maybe some example code? I'm a bit of a
noob with this in general. Thank you.



On Sep 14, 11:05 am, Thomas Plochprofipl...@googlemail.comwrote:

The easiest way would be an AJAX action that renders the element with
the given POST data. The you can just use the rendered HTML and inject
it into the DOM.



Kind regards
Thomas



Am 14.09.2011 16:55, schrieb 8vius:



Hey all, got a little problem here. I wanna do something similar to
what twitter does when you post a new tweet, that it automatically
adds itself to the stream. I have made an element for this, the
element receives my model data and sets it up properly but I'm not
sure how to pass in the data from Jquery (I receive a JSON object). So
what are my options here? How can I accomplish this?




--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.



To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Rendering an element with Jquery

2011-09-14 Thread 8vius
And how can I pass an array into the view? I do it in other parts of
my code just doing $this-render('element', $data) but it's giving me
an error here

On Sep 14, 11:59 am, Thomas Ploch profipl...@googlemail.com wrote:
 The RequestHandler Component is not doing any requests, it just verifies
 that the current request indeed is an AJAX request, so you can check in
 an action and i.e. render an element with an AJAX layout instead of
 rendering the whole view. You can of course generate the HTML with
 javascript using the returned JSON object 
 (http://api.jquery.com/jQuery.template). But in my oppinion it is way
 easier to do the data handling in the action, and just render the
 element's HTML with $this-render() and use that in the success callback
 of the jQuery $.post method, appending the rendered HTML into a DOM node.

 Am 14.09.2011 17:51, schrieb 8vius:







  hmmm I don't use the request handler to do my ajax requests, I just
  echo out the response, would that work ? doing echo $this-render()?

  On Sep 14, 11:36 am, Thomas Plochprofipl...@googlemail.com  wrote:
  As an addition, check outhttp://book.cakephp.org/view/980/render

  Am 14.09.2011 17:14, schrieb 8vius:

  Can you be a little more explicit? I have my ajax action set up that
  will return a json encoded array. How can I get the html for the
  element from my controller? Maybe some example code? I'm a bit of a
  noob with this in general. Thank you.

  On Sep 14, 11:05 am, Thomas Plochprofipl...@googlemail.com    wrote:
  The easiest way would be an AJAX action that renders the element with
  the given POST data. The you can just use the rendered HTML and inject
  it into the DOM.

  Kind regards
  Thomas

  Am 14.09.2011 16:55, schrieb 8vius:

  Hey all, got a little problem here. I wanna do something similar to
  what twitter does when you post a new tweet, that it automatically
  adds itself to the stream. I have made an element for this, the
  element receives my model data and sets it up properly but I'm not
  sure how to pass in the data from Jquery (I receive a JSON object). So
  what are my options here? How can I accomplish this?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Rendering an element with Jquery

2011-09-14 Thread 8vius
I meant $this-element('element', $data);

On Sep 14, 12:06 pm, 8vius lmd...@gmail.com wrote:
 And how can I pass an array into the view? I do it in other parts of
 my code just doing $this-render('element', $data) but it's giving me
 an error here

 On Sep 14, 11:59 am, Thomas Ploch profipl...@googlemail.com wrote:







  The RequestHandler Component is not doing any requests, it just verifies
  that the current request indeed is an AJAX request, so you can check in
  an action and i.e. render an element with an AJAX layout instead of
  rendering the whole view. You can of course generate the HTML with
  javascript using the returned JSON object 
  (http://api.jquery.com/jQuery.template). But in my oppinion it is way
  easier to do the data handling in the action, and just render the
  element's HTML with $this-render() and use that in the success callback
  of the jQuery $.post method, appending the rendered HTML into a DOM node.

  Am 14.09.2011 17:51, schrieb 8vius:

   hmmm I don't use the request handler to do my ajax requests, I just
   echo out the response, would that work ? doing echo $this-render()?

   On Sep 14, 11:36 am, Thomas Plochprofipl...@googlemail.com  wrote:
   As an addition, check outhttp://book.cakephp.org/view/980/render

   Am 14.09.2011 17:14, schrieb 8vius:

   Can you be a little more explicit? I have my ajax action set up that
   will return a json encoded array. How can I get the html for the
   element from my controller? Maybe some example code? I'm a bit of a
   noob with this in general. Thank you.

   On Sep 14, 11:05 am, Thomas Plochprofipl...@googlemail.com    wrote:
   The easiest way would be an AJAX action that renders the element with
   the given POST data. The you can just use the rendered HTML and inject
   it into the DOM.

   Kind regards
   Thomas

   Am 14.09.2011 16:55, schrieb 8vius:

   Hey all, got a little problem here. I wanna do something similar to
   what twitter does when you post a new tweet, that it automatically
   adds itself to the stream. I have made an element for this, the
   element receives my model data and sets it up properly but I'm not
   sure how to pass in the data from Jquery (I receive a JSON object). So
   what are my options here? How can I accomplish this?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Rendering an element with Jquery

2011-09-14 Thread 8vius
Also, I'm testing your solution, and it is outputting the element html
data but for some reason it's outputting a bunch of other data from
the controller, like:

$___dataForView =   array()
$loadHelpers=   true
$cached =   false
$session=   SessionHelper
SessionHelper::$helpers = array
SessionHelper::$__active = true
SessionHelper::$valid = false
SessionHelper::$error = false
SessionHelper::$_userAgent = 082aaf941d57844d51008967f7e4ca5a

and it's a lot of that

On Sep 14, 12:07 pm, 8vius lmd...@gmail.com wrote:
 I meant $this-element('element', $data);

 On Sep 14, 12:06 pm, 8vius lmd...@gmail.com wrote:







  And how can I pass an array into the view? I do it in other parts of
  my code just doing $this-render('element', $data) but it's giving me
  an error here

  On Sep 14, 11:59 am, Thomas Ploch profipl...@googlemail.com wrote:

   The RequestHandler Component is not doing any requests, it just verifies
   that the current request indeed is an AJAX request, so you can check in
   an action and i.e. render an element with an AJAX layout instead of
   rendering the whole view. You can of course generate the HTML with
   javascript using the returned JSON object 
   (http://api.jquery.com/jQuery.template). But in my oppinion it is way
   easier to do the data handling in the action, and just render the
   element's HTML with $this-render() and use that in the success callback
   of the jQuery $.post method, appending the rendered HTML into a DOM node.

   Am 14.09.2011 17:51, schrieb 8vius:

hmmm I don't use the request handler to do my ajax requests, I just
echo out the response, would that work ? doing echo $this-render()?

On Sep 14, 11:36 am, Thomas Plochprofipl...@googlemail.com  wrote:
As an addition, check outhttp://book.cakephp.org/view/980/render

Am 14.09.2011 17:14, schrieb 8vius:

Can you be a little more explicit? I have my ajax action set up that
will return a json encoded array. How can I get the html for the
element from my controller? Maybe some example code? I'm a bit of a
noob with this in general. Thank you.

On Sep 14, 11:05 am, Thomas Plochprofipl...@googlemail.com    wrote:
The easiest way would be an AJAX action that renders the element with
the given POST data. The you can just use the rendered HTML and 
inject
it into the DOM.

Kind regards
Thomas

Am 14.09.2011 16:55, schrieb 8vius:

Hey all, got a little problem here. I wanna do something similar to
what twitter does when you post a new tweet, that it automatically
adds itself to the stream. I have made an element for this, the
element receives my model data and sets it up properly but I'm not
sure how to pass in the data from Jquery (I receive a JSON object). 
So
what are my options here? How can I accomplish this?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Rendering an element with Jquery

2011-09-14 Thread Thomas Ploch

erm, the same as you would set it to any other view:

?php

function action() {
[...]
// inside your action
$myArray = array('tweet' = 'feep feep feep');
// or $myArray = json_decode($yourJsonObject, true);

// Set the variable just like any other var
$this-set(compact('myArray'));

// This will render the element in '/views/elements/element.ctp' with 
the data in $myArray
// So you can access $myArray in the element just like a normal 
view var

$this-render('/elements/element');
}


Am 14.09.2011 18:06, schrieb 8vius:

And how can I pass an array into the view? I do it in other parts of
my code just doing $this-render('element', $data) but it's giving me
an error here

On Sep 14, 11:59 am, Thomas Plochprofipl...@googlemail.com  wrote:

The RequestHandler Component is not doing any requests, it just verifies
that the current request indeed is an AJAX request, so you can check in
an action and i.e. render an element with an AJAX layout instead of
rendering the whole view. You can of course generate the HTML with
javascript using the returned JSON object 
(http://api.jquery.com/jQuery.template). But in my oppinion it is way
easier to do the data handling in the action, and just render the
element's HTML with $this-render() and use that in the success callback
of the jQuery $.post method, appending the rendered HTML into a DOM node.

Am 14.09.2011 17:51, schrieb 8vius:








hmmm I don't use the request handler to do my ajax requests, I just
echo out the response, would that work ? doing echo $this-render()?



On Sep 14, 11:36 am, Thomas Plochprofipl...@googlemail.comwrote:

As an addition, check outhttp://book.cakephp.org/view/980/render



Am 14.09.2011 17:14, schrieb 8vius:



Can you be a little more explicit? I have my ajax action set up that
will return a json encoded array. How can I get the html for the
element from my controller? Maybe some example code? I'm a bit of a
noob with this in general. Thank you.



On Sep 14, 11:05 am, Thomas Plochprofipl...@googlemail.com  wrote:

The easiest way would be an AJAX action that renders the element with
the given POST data. The you can just use the rendered HTML and inject
it into the DOM.



Kind regards
Thomas



Am 14.09.2011 16:55, schrieb 8vius:



Hey all, got a little problem here. I wanna do something similar to
what twitter does when you post a new tweet, that it automatically
adds itself to the stream. I have made an element for this, the
element receives my model data and sets it up properly but I'm not
sure how to pass in the data from Jquery (I receive a JSON object). So
what are my options here? How can I accomplish this?




--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.



To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Rendering an element with Jquery

2011-09-14 Thread 8vius
Thank you very much Thomas, got the response back properly with the
html code, still getting some errors so gotta see what's wrong with
that.

On Sep 14, 12:14 pm, Thomas Ploch profipl...@googlemail.com wrote:
 erm, the same as you would set it to any other view:

 ?php

      function action() {
          [...]
          // inside your action
          $myArray = array('tweet' = 'feep feep feep');
          // or $myArray = json_decode($yourJsonObject, true);

          // Set the variable just like any other var
          $this-set(compact('myArray'));

 // This will render the element in '/views/elements/element.ctp' with
 the data in $myArray
          // So you can access $myArray in the element just like a normal
 view var
          $this-render('/elements/element');
      }

 Am 14.09.2011 18:06, schrieb 8vius:







  And how can I pass an array into the view? I do it in other parts of
  my code just doing $this-render('element', $data) but it's giving me
  an error here

  On Sep 14, 11:59 am, Thomas Plochprofipl...@googlemail.com  wrote:
  The RequestHandler Component is not doing any requests, it just verifies
  that the current request indeed is an AJAX request, so you can check in
  an action and i.e. render an element with an AJAX layout instead of
  rendering the whole view. You can of course generate the HTML with
  javascript using the returned JSON object 
  (http://api.jquery.com/jQuery.template). But in my oppinion it is way
  easier to do the data handling in the action, and just render the
  element's HTML with $this-render() and use that in the success callback
  of the jQuery $.post method, appending the rendered HTML into a DOM node.

  Am 14.09.2011 17:51, schrieb 8vius:

  hmmm I don't use the request handler to do my ajax requests, I just
  echo out the response, would that work ? doing echo $this-render()?

  On Sep 14, 11:36 am, Thomas Plochprofipl...@googlemail.com    wrote:
  As an addition, check outhttp://book.cakephp.org/view/980/render

  Am 14.09.2011 17:14, schrieb 8vius:

  Can you be a little more explicit? I have my ajax action set up that
  will return a json encoded array. How can I get the html for the
  element from my controller? Maybe some example code? I'm a bit of a
  noob with this in general. Thank you.

  On Sep 14, 11:05 am, Thomas Plochprofipl...@googlemail.com      wrote:
  The easiest way would be an AJAX action that renders the element with
  the given POST data. The you can just use the rendered HTML and inject
  it into the DOM.

  Kind regards
  Thomas

  Am 14.09.2011 16:55, schrieb 8vius:

  Hey all, got a little problem here. I wanna do something similar to
  what twitter does when you post a new tweet, that it automatically
  adds itself to the stream. I have made an element for this, the
  element receives my model data and sets it up properly but I'm not
  sure how to pass in the data from Jquery (I receive a JSON object). So
  what are my options here? How can I accomplish this?

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php