Sunday, January 4, 2009

Re: Adding table row with AJAX

On Sun, Jan 4, 2009 at 8:32 AM, Steven Wright <rhythmicdevil@gmail.com> wrote:
>
> Still banging on this row problem. How do I get the content of an element
> from my controller so that I can echo it to the view? Is the completely
> wrong approach? What is the correct way to achieve this? What is it exactly
> that CakePHP wants me to do?
>
> At this point I am ready to give up on CakePHP and just write a function in
> my controller that returns the HTML I need, the old fashioned way because I
> would be done in about 10 minutes. However that sort of defeats the purpose
> of using CakePHP.
>
>
> CONTROLLER EDIT ACTION
>
> function edit()
> {
> $this->pageTitle = 'Edit Page';
>
>
> if($this->RequestHandler->isAjax())
> {
> // HOW DO I ECHO THE CONTENT OF THE ROW ELEMENT
> INSTEAD OF THE ECHO BELOW?
> // THERE HAS TO BE A DRY WAY TO DO THIS.
>
> echo '<tr id="'.$_POST['row_count'].'"><td>Col1 ::
> Row '.$_POST['row_count'].'</td><td>Col2 :: Row
> '.$_POST['row_count'].'</td></tr>';
> $this->autoRender = false;
> }
>
> // Handle the edit stuff
>
> }
>
>
>
> EDIT VIEW
>
> <table id="the_table">
> <?php
> echo $this->renderElement('row', array('row_count' => 0));
> ?>
> </table>
>
> <div id="the_button">Click</div>
>
>
> ROW ELEMENT
>
> <tr id="<?php echo $row_count; ?>">
> <td>Col 1 :: Row <?php echo $row_count; ?></th>
> <td>Col 2 :: Row <?php echo $row_count; ?></th>
> </tr>
>

OK, I'll leave out $row_count for now. Put this markup in a view named
edit_ajax.ctp

<tr>
<td>Col 1 :: Row <?php echo $variable_2; ?></th>
<td>Col 2 :: Row <?php echo $variable_2; ?></th>
</tr>

controller:
if ($this->RequestHandler->isAjax())
{
$this->set('variable_1', 'foo);
$this->set('variable_2', 'bar');
$this->render('edit_ajax');
}

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