cakephp - Calling a element after login -
i have post index view calling element content input field comment.
i call in way
<?php echo $this->element('addcomment', array('post_id' => $post['post']['id'])); ?>
this work fine, pass post id parameter, in addcomment element, because post_id input field hidden in addcomment. , of course dont want user type post id.
i have set authorization mechanism in order allow adding comment user identified (connected).
when non-connected user try add comment, receives login screen.
after login, redirected add commment form. problem in mean time loose value of post_id variable.
rem: if user connected before adding comments post, works.
dont hesitate contact me in case explanation not clear or if need more information.
this addcomment element
<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>
as per understand problem. can use session variable store post id should not affected if user logs in. , using session can redirect user particular post after login.
set session value before redirecting user login.
$this->session->write('last_post_id',your_post_id);
redirect user post if user logged in , if find session value not empty.
if ($this->session->check('last_post_id') && $this->session->read('last_post_id') != '') { $this->redirect(your_url_to_post . '?postid=' . $this->session->read('last_post_id')); exit; }else{ //normal redirection }
hope you. unset session last_post_id after redirection , if no longer required.
Comments
Post a Comment