• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
undefined variable

#8
<?php
class Posts extends CI_Controller{

   public function index()
  {
       $data['title']='Latest Posts';
       $data['posts']=$this->Post_model->get_posts();
       $this->load->view('templates/header');
       $this->load->view('posts/index',$data);
       $this->load->view('templates/footer');
   }
   

public function view($slug=NULL)
   {
       $data['post']=$this->Post_model->get_posts($slug);
       if(empty($data['post'])){
           show_404();
       }
       $data['title']=$data['post']['title'];
       $this->load->view('templates/header');
       $this->load->view('posts/index',$data);
       $this->load->view('templates/footer');
   }






The problem lies in the bold. You are loading the same view file for both method calls. For the index method your variable is posts and for your view method your variable is post
Reply


Messages In This Thread
undefined variable - by anmol - 03-25-2017, 12:39 PM
RE: undefined variable - by Wouter60 - 03-25-2017, 11:25 PM
RE: undefined variable - by anmol - 03-25-2017, 11:35 PM
RE: undefined variable - by Wouter60 - 03-25-2017, 11:49 PM
RE: undefined variable - by anmol - 03-25-2017, 11:56 PM
RE: undefined variable - by anmol - 03-25-2017, 11:58 PM
RE: undefined variable - by Wouter60 - 03-26-2017, 03:11 AM
RE: undefined variable - by ChicagoPhil - 03-26-2017, 01:06 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.