BlenderStyle wrote:
> => 'posts_div')) to update the div. How does the add method come into
> play when updating the div? Does the add view end up being used to
> update posts_div? Do I have to render a partial. (I'm not really sure
> what render a partial means, but I'm willing to learn if it's
> necessary.)

Here's how I do it: make the add view update the index list. When you
say "render a partial", it may mean rendering an element inside a view.
Below are sample codes:

INSIDE views/posts

***index.thtml***
<fieldset>
        <legend>Posts</legend>
        <a name="list"></a>
        <div id="post_list">
            <?php
            $pagination->setPaging($paging);
            echo $this->renderElement('posts/ajax_post_list', $params);
            echo $javascript->codeBlock('initDrag();');
            echo $this->renderElement('pagination',$paging);
            ?>
        </div>
        <p><a href="#add" style="font-size:11px;font-weight:normal;"
onclick="javascript:new Effect.Appear('add_post');"><?php echo
$html->image('add.gif', array('alt'=>'Add A Post', 'border'=>'0',
'width'=>'6', 'height'=>'6')); ?> Add A Post</a></p>
</fieldset>

<a name="add"></a>
<div id="add_post" style="display:none">
<?php
$arr = array(
  'post' => array(
    'title'=>'',
    'body'=>''
  )
);
$params = array('act'=>'add', 'controller'=>'posts', 'data'=>$arr);
echo $this->renderElement('posts/ajax_post_edit', $params);
    ?>
</div>

***add.thtml***
<?php
$data = $this->controller->Post->findAll(null, null, 'id');
$params = array('controller'=>'posts', 'data'=>$data);
echo $this->renderElement('posts/ajax_post_list', $params);
?>

INSIDE views/elements/posts

***ajax_post_list.thtml***
<!-- elements::ajax_post_list start -->
<p class="caption">Here is a list of the posts.</p>
<form name="frmList" id="frmList">
<ul>
  <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <?php foreach ($data as $row):
    $Post = $row['Post'];
    ?>
    <tr>
      <td><li class="list"><b><?php echo $Post['title'];
?></b></li></td>
    </tr>
    <?php endforeach; ?>
  </table>
</ul>
</form>
<!-- elements::ajax_post_list end -->

***ajax_post_edit.thtml***
<!-- elements::ajax_post_edit start -->
<?php $actText = ucfirst($act); ?>
<fieldset>
  <legend><?php echo $actText; ?> Post</legend>
    <form onsubmit="return false;">
      <?php echo $html->hidden('Post/id'); ?>
      <table width="100%">
      <tr valign="top">
        <td>Title</td>
        <td><?php echo $html->input('Post/title', array("size"=>30,
"maxlength"=>255, "id"=>$act.'Title')); ?></td>
        <td>Message</td>
        <td><?php echo $html->input('Post/body', array("size"=>30,
"maxlength"=>255, "id"=>$act.'Body')); ?></td>
      </tr>
      <?php
      if ($actText == "Add") {
      ?>
      <tr>
        <td colspan="2" align="left"><?php echo $ajax->submit('Save',
array('url' => 'add', 'update' => 'post_list', 'complete' => 'new
Effect.Fade(\'add_post\');stripe();initDrag();')); ?>
        <input type="reset" name="reset" class="button"
value="Clear"></td>
      </tr>
      <?php
      } else { ?>
      <tr>
        <td colspan="2" align="left"><?php echo $ajax->submit('Save',
array('url' => 'edit', 'update' => 'post_list', 'complete' => 'new
Effect.Fade(\'edit_post\');stripe();initDrag();')); ?></td>
      </tr>
      <?php
      }
      ?>
      </table>
    </form>
    <p>[ <a style="font-weight:normal;font-size:10px;"
href="javascript:new Effect.Fade('<?php echo $act;
?>_post');void(0);">Hide</a> ]</p>
</fieldset>
<!-- elements::ajax_post_edit end -->

Note: This element handles both the add and edit functions but let's
concentrate on the add function only.

Here's what happens:
1. When the index view is loaded, it initially displays a list of post
titles.
2. When the add link is clicked, the ajax-ed add form (add element) is
shown (it was hidden from initial view).
3. When the user clicks on the Save button, the controller saves the
data and renders the add view that updates the ajax-ed index list (list
element). Hence, the list was updated without page refresh.

I hope these helps.

Regards,
Reine


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to