Sunday, January 4, 2009

Re: Adding table row with AJAX

On Sat, Jan 3, 2009 at 11:15 PM, Steven Wright <rhythmicdevil@gmail.com> wrote:
>
> Actually this works in place of the dummy file
>
> $this->autoRender = false;

Yes, that's correct. The reason (AFAIK) that RequestHandler doesn't
suppress that automatically is that one should use a .ctp file for the
output. You're better off setting a variable in your controller and
handing it off to a view:

$this->set('row_count', $row_count);
$this->set('the_content', $the_content);
$this->render('the_view_ajax');

the_view_ajax:
<tr id="row<?= $row_count ?>"><td><?= $the_content ?></td></tr>

This keeps HTML cruft out of your methods, which is always a Very Good Thing.

I think RequestHandler might use a view named, 'the_view' + '_ajax' if
it finds it, so you might not need the render() call.

I'm also pretty sure it takes care of setting $layout = 'ajax', btw.
Try removing that line and see if everything still works.

(yeah, I'm too lazy to go check that. What do you expect from someone
who uses short tags? ;-)

--~--~---------~--~----~------------~-------~--~----~
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: