我有一個帖子索引視圖調用一個元素的內容輸入字段進行評論。登錄後調用一個元素
我把它用這種方式
<?php echo $this->element('addcomment', array('post_id' => $post['Post']['id'])); ?>
這項工作很好,我傳遞的帖子ID參數,在addcomment元素,因爲POST_ID輸入字段隱藏在addcomment。當然我不希望用戶輸入帖子ID。
我已經設置了授權機制,以允許向標識(已連接)的用戶添加評論。
當未連接的用戶嘗試添加評論時,他會收到登錄屏幕。
登錄後,他被重定向到添加提交表單。問題在於,它同時失去了post_id變量的值。
Rem:如果在向帖子添加評論之前連接了用戶,它就會起作用。
如果我的解釋不清楚或者您需要更多信息,請不要猶豫與我聯繫。
這是我addcomment元素
<div class="Addcomment form">
<?php
echo $this->Form->create('Comment', array(
'url' => array('controller' => 'comments', 'action' => 'add')
)); ?>
<fieldset>
<legend><?php echo __('Add Comment'); ?></legend>
<?php if (isset($current_user['id']) && isset($post_id)): ?>
<?php $this->request->data['Comment']['user_id'] = $current_user['id']; ?>
<?php $this->request->data['Comment']['post_id'] = $post_id; ?>
<?php echo $this->Form->input('post_id', array('type' => 'hidden')); ?>
<?php echo $this->Form->input('user_id', array('type' => 'hidden')); ?>
<?php else: echo $this->Form->input('post_id'); ?>
<?php endif; ?>
<?php echo $this->Form->input('content', array('class' => 'comment')); ?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>