DB Query issues |
[eluser]stevefink[/eluser]
Can anyone tell me why $photos in my view is not being seen by my view? I keep getting a notice that it is an undefined variable. I've made sure $photos is being populated properly in the model/controller: Here's my controller: Code: function get_photos() My model: Code: function get_photos() $photos is still undefined after $this->load->view('console/vehicle_photos_view', $photos); Any idea?
[eluser]Seppo[/eluser]
Try this on your controller Code: function get_photos()
[eluser]stevefink[/eluser]
No results, unfortunately. Is there a reason $data needs to be pushed in versus $photos? Is the view code searching for $data? I've done it before with arbitrary array names.
[eluser]stevefink[/eluser]
I added a log_message directive into my controller to grab the data, and the array is indeed being populated. The view however, does not wish to do anything with this data. function get_photos() { // get all photo filesystem locations. $photos = $this->autodb->get_photos(); log_message('debug', "This is a test: " . print_r($photos, TRUE)); //$this->load->view('console/vehicle_photos_view', $data); } and my logs: DEBUG - 2007-08-21 18:25:49 --> This is a test: Array ( [0] => Array ( [photoloc] => ./uploads/IMG0595.JPG ) [1] => Array ( [photoloc] => ./uploads/IMG0596.JPG ) [2] => Array ( [photoloc] => ./uploads/IMG0598.JPG ) ) Any ideas folks?
[eluser]Rick Jolly[/eluser]
How are you referencing the array in your view? Typically the data you send to your view is a key-value array. You are sending a numerically indexed array to the view. Personally, I'd just send the result array to the view. The extra loop in the model isn't necessary.
[eluser]BravoAlpha[/eluser]
[quote author="stevefink" date="1187752934"]Is there a reason $data needs to be pushed in versus $photos?[/quote] I believe that Seppo is just pointing out that you're not passing an associative array. ($data is just commonly used.) http://ellislab.com/codeigniter/user-gui...oader.html Quote:$this->load->view('file_name', $data, true/false)
[eluser]Michael Wales[/eluser]
How are you trying to echo them out in your view? Looks like the controller and model are fine (although I would put them in an associative array anyways, what if you need to pass more data than just these photos to the view?). Paste your view code.
[eluser]stevefink[/eluser]
I got this resolved, btw. The issue was, in my model I was converting the data to an array and then passing that into the view which was causing issues (I think.) Final result looks like this: Code: <?php foreach($photos->result() as $photo): ?> |
Welcome Guest, Not a member yet? Register Sign In |