CodeIgniter View Hack

I ran into what seems like it might a bug in CodeIgniter’s view loading. (Specifically in the extraction of a data array into the local scope for that view.) I had pulled out a piece of HTML that was repeated a lot into a separate view file in order to call it more easily in the main view file. The data array I was passing in had certain keys that were sometimes present, sometimes not present. I discovered that if I called the view once when the keys were present, and then a second time when the keys were not present, rather than seeing no value for the keys (the expected result), the view saw the values from the previous call. My eventual soultion was to replace my view loading line $this->load->view('view_name', $data); with $this->load->view('view_name',Array('d'=>$data)); Loading the view in this second method meant CodeIgniter was only extracting one symbol ($d) into the global sope of the view I was loading. Since this symbol got replaced on every call, my problem went away. The kinda-lame part, however, is that the view now needs to reference pieces of data as $d['piece_of_data'] instead of simply $piece_of_data



Me on a beautiful early spring day in Napa, in a field of mustard.

Steven Lybeck


  • ph: 415.830.3274

  • View Steven Lybeck's profile on LinkedIn
  • My status