php - Unable to access data in view codeigniter -


i have 3 controller methods name blog, load_messages , load_comments. want pull comments when user clicks on button. post id passed method name load_comments if load view named blog gives error because have passed data view. want pass data is comments controller.

the functions are:

public function blog() {      $user_session_email = $this -> session -> userdata('user_email','name','id');     if(!$user_session_email) {         redirect('/');     }       $user_data = $this -> users_model -> myaccount([         'id' => $this -> session -> userdata('id'),         'name' => $this -> session -> userdata('name'),         'email' => $this -> session -> userdata('user_email'),     ]);     $data["persoanl"] = $user_data;      $returned_result = $this -> users_model -> load_messages();     $messages["message"] = $returned_result['message'];      $this -> load -> view('users/inc/header', $data);     $this -> load -> view('users/inc/blog_form', $data);     $this -> load -> view('users/blog', $messages);     $this -> load -> view('users/inc/footer'); }  public function load_messages() {     $returned_result = $this -> users_model -> load_messages();     $messages["message"] = $returned_result["message"];     $messages['id'] = $this -> load_comments();     $this -> load -> view('users/blog', $messages); }  public function load_comments() {     $messages['id'] = $this -> input -> post('post_id');     $this -> load -> view('users/blog', $messages); } 

in last method want pass $message variable, when pass value other functions in blog view loaded different parameters $messages['message'], generates error says $message undefined on blog view page if remove last method work perfectly. should how pass data blog?

blog view code

            <?php              foreach($message $blog) :         ?>         <div class="row blog_post<?php echo $blog -> blog_id; ?>" id="blog_posts">              <div class="col-lg-1 col-md-2 col-sm-2 col-xs-3 user_blog_image">                 <?php if($blog -> profile_image == null) { ?>                     <img src="<?php echo base_url(); ?>public/dist/img/user2-160x160.jpg" alt="user image">                 <?php } else { ?>                     <img src="<?php echo base_url().$blog -> profile_image; ?>"  alt="user image">                 <?php } ?>             </div> <!-- end of user blog image -->              <div class="col-lg-11 col-md-10 col-sm-10 col-xs-9 post_message">                 <?php if($blog -> id == $this -> session -> userdata('id')) : ?>                 <a class="pull-right" onclick="delete_post('<?php echo $blog -> blog_id; ?>', '<?php echo base_url('users/delete_post'); ?>')">                     &times;                 </a>                 <?php endif; ?>                  <p>                      <?php echo $blog -> message; ?>                  </p>                 <span class="pull-left">                      <small> posted by: <?php echo $blog -> name; ?></small>                  </span>                 <a onclick="get_comments(this.id, '<?php echo base_url('users/load_comments'); ?>')" class="stop_interval" id="<?php echo $blog -> blog_id; ?>">                      <i class='fa fa-comment' aria-hidden='true'></i> view comments                 </a>                 <a onclick="update_like('<?php echo $blog -> blog_id; ?>', '<?php echo base_url('users/update_like'); ?>')">                     <i class='fa fa-thumbs-up' aria-hidden='true'></i> likes (<small><?php echo $blog -> likes; ?></small>)                 </a>              </div> <!-- end of post message -->              <div class="col-lg-offset-1 col-lg-11 comment_field">                  <div class="show_comments col-lg-12 col-md-12 col-sm-12 col-xs-12" id="show_comments<?php echo $blog -> blog_id; ?>">                     <?php echo $id; ?>                     <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 commentor_pic">                         <img src="<?php echo base_url(); ?>public/dist/img/user2-160x160.jpg" alt="user image">                     </div> <!-- end of commentor picture -->                     <div class="col-lg-11 col-md-11 col-sm-11 col-xs-11 comment">                         <p> lorem ipsum dummy text of printing , typesetting industry. lorem ipsum has been industry's standard dummy text ever since 1500s, when unknown printer took galley of type , scrambled make type specimen book. </p>                         <p> <small> posted by: rashid khokhar </small> </p>                     </div> <!-- end of commentor picture -->                 </div> <!-- end of show comments -->                   <form method="post" id="comment_form<?php echo $blog -> blog_id; ?>">                     <input type="text" id="blog_comment<?php echo $blog -> blog_id; ?>" required name="comment_field" class="form-control" placeholder="type comment">                     <button type="submit" id="cmntbtn<?php echo $blog -> blog_id; ?>" class="btn btn-primary"><i class="fa fa-share" aria-hidden="true"></i></button>                 </form>             </div> <!-- end of comment field -->          </div>         <script type="text/javascript" src="<?php echo base_url('public/dist/js/jquery.js'); ?>"></script>         <script type="text/javascript" src="<?php echo base_url(); ?>public/dist/js/custom.js"></script>         <script type="text/javascript">             comment_blog('<?php echo $blog -> blog_id; ?>', '<?php echo base_url('users/comment_blog'); ?>');             jquery( "#show_comments<?php echo $blog -> blog_id; ?>" ).each(function( value ) {                 jquery(this).hide();             });         </script>          <?php endforeach; ?>     </div>  </div> 

in load_comments method, need fetch data database using model.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -