Welcome Guest, Not a member yet? Register   Sign In
store value temporarily in controller and retrieve that value on each time page refreshed
#1

[eluser]Unknown[/eluser]
I am trying to pass some values(ticket_id) from view page to controller using hidden fields of form and according to that ticket_id corresponding page is displayed. this part is working fine but the problem is when I am refreshing the page I am unable to store that ticket_id in the controller and in my view page nothing is displayed.
I tried session but its not working..
here is my first view page..
Code:
<style type="text/css">
table {
    margin:0 auto;
    font-size: 12px;
}
td {
    padding:.5em 1em;
    border:2px solid #e2e2e2;
}
th{
    font-size: 14px;
    text-decoration: bold;
    text-align: center;
}
  </style>
  [removed]
  $(function(){
  $('tr:odd').css("background-color","#e2e2e2");
  });
  [removed]

<?php $count=Template::get('count'); ?>
  <?php if($count > 0) : ?>
  <h2>Here are your tickets </h2>
  <table name = "ticket_table" id = "myTickets">
     <tr>
            <th>Title</th>      
            <th>Category</th>
            <th>Priority</th>        
            <th>Date Of Post</th>        
            <th>Status</th>        
     </tr>
  &lt;?php foreach($result->result_array() as $ticketRow) : ?&gt;
  <tr>
     <td>&lt;?php echo word_wrap($ticketRow['title'],15); ?&gt;</td>
     <td>&lt;?php echo $ticketRow['category']; ?&gt;</td>
     <td>&lt;?php echo $ticketRow['priority']; ?&gt;</td>
     <td>&lt;?php echo $ticketRow['date']; ?&gt;</td>
     <td>&lt;?php echo $ticketRow['post_status']; ?&gt;</td>
  <td>&lt;?php echo form_open('/helpdesk/full_post_view'); ?&gt;
  &lt;?php echo form_hidden('ticket_id',$ticketRow['id']); ?&gt;
  &lt;?php echo form_hidden('post_content',$ticketRow['post_content']); ?&gt;
  &lt;?php echo form_submit('submit', 'Full View'); ?&gt;
  &lt;?php echo form_close(); ?&gt;</td>
</tr>
&lt;?php endforeach; ?&gt;
</table>
&lt;?php endif; ?&gt;

here is my controller code :-
Code:
function full_post_view(){
                $data= array(
                    'ticket_id' => $this->input->post('ticket_id'),
                    'post_content' => $this->input->post('post_content')
                );
                session_start();
                $this->session->set_userdata($data);
                 $ticket_id = ($this->input->post('ticket_id')) ? $this->input->post('ticket_id') : $this->session->userdata('ticket_id');
                // $post_content = ($this->input->post('post_content')) ? $this->input->post('post_content') : $this->session->userdata('post_content');    
                $post_content = ($this->input->post('post_content'));
                $this->load->model('helpdesk_model');
                $all_comments = $this->helpdesk_model->fetchComments($ticket_id);
                $is_post_closed = $this->helpdesk_model->fetchPostStatus($ticket_id);                
                if($all_comments->num_rows > 0)  {
                    foreach ($all_comments->result() as $comments_value) {
                        $comments = $comments_value->comments;
                    }
                    $count=1;
                    Template::set('all_comments',$all_comments);
                    Template::set_view('helpdesk/full_post_view');
                }
                else {
                    $count=0;
                    Template::set('post_content',$this->input->post('post_content'));
                }                
                Template::set('is_post_close',$is_post_closed);
                //Template::set('ticket_id',$ticket_id);
                Template::set('is_post_closed',$is_post_closed);
                Template::set('post_content',$post_content);
                Template::set('count',$count);                
                Template::set('is_post_closed',$is_post_closed);                
                Template::render();
        }

here is my another view page :- full_post_view.php
Code:
&lt;?php $ticket_id = $this->session->userdata('ticket_id'); ?&gt;
&lt;?php $post=Template::get('post_content'); ?&gt;
&lt;?php  $ticket_id=Template::get('ticket_id'); ?&gt;
&lt;?php  $is_close = Template::get('is_close'); ?&gt;
<h4>Your Problem :- </h4>
&lt;?php echo $post; ?&gt;
<hr/>
&lt;?php foreach ($is_post_closed->result() as  $value) {
$is_close = $value->is_close;
} ?&gt;
&lt;?php if(Template::get('count') > 0) : ?&gt;
&lt;?php foreach($all_comments->result_array() as $commentsRow) : ?&gt;
  &lt;?php echo word_wrap($commentsRow['comments'],15); ?&gt;
  &lt;?php echo " by->"; ?&gt;
  &lt;?php echo $commentsRow['username']; ?&gt;
  &lt;?php echo $commentsRow['role_name']; ?&gt;
  <hr/>
&lt;?php endforeach; ?&gt;
&lt;?php else : ?&gt;
  <br/>
  No Comments Yet
&lt;?php endif; ?&gt;
&lt;?php if($is_close == 0 ) : ?&gt;
  &lt;?php echo form_open('helpdesk/newComment'); ?&gt;
  &lt;?php echo form_hidden('ticket_id',$ticket_id); ?&gt;
  &lt;?php  echo form_hidden('post_content', $post); ?&gt;
  &lt;?php echo form_textarea('comment_from_user'); ?&gt;
  &lt;?php echo form_submit('submit', 'Comment '); ?&gt;
  &lt;?php echo form_close(); ?&gt;
&lt;?php endif; ?&gt;
&lt;?php if($is_close==0) : ?&gt;
&lt;?php echo form_open('helpdesk/closePost'); ?&gt;
&lt;?php echo form_hidden('ticket_id', $ticket_id); ?&gt;
&lt;?php  echo form_hidden('post_content', $post); ?&gt;
&lt;?php echo form_submit('submit','close post'); ?&gt;
&lt;?php echo form_close(); ?&gt;
&lt;?php else : ?&gt;
&lt;?php echo form_open('helpdesk/reopenPost'); ?&gt;
&lt;?php echo form_hidden('ticket_id', $ticket_id); ?&gt;
&lt;?php echo form_submit('submit','Reopen post'); ?&gt;
&lt;?php echo form_close(); ?&gt;
&lt;?php endif; ?&gt;

I am using bonfire..
#2

[eluser]jakelehner[/eluser]
You're storing the values in the user's session, but always pulling them from the POST data. When you refresh, you lose your post data.

Quick and dirty, use flash data instead of the session user data. At the top of the controller you can use an if statement to see if the POST data is populated. If so, take the values from there. If not, try and get it from the flash data. If that doesn't work, throw an error.

And, of course, you'll need to reset or persist the flash data every time since it's only available for one page load.




Theme © iAndrew 2016 - Forum software by © MyBB