Pass multiple arrays/datasets into view... |
[eluser]dharmy[/eluser]
Hi there I'v been working on this all afternoon but am not having much luck. Simply put, I have a view that is accepting data from 2 queries (into two different select fields). The code for the controller - can anyone tell me where I am going wrong? Code: public function ShowForm() I don't know how the view should be fetching the data. At the moment I have a country list working OK, but not the 2nd array / dataset: Code: <form>
[eluser]CroNiX[/eluser]
I think it was recently discovered that the parser won't parse views that are returned (using the 3rd parameter, TRUE, for loading a view) because the parsing actually takes place in the output class of CI, which is bypassed when returning a view.
[eluser]dharmy[/eluser]
Am a bit of a newbie... so you're saying that I should set it to false? I'm still now sure how the view code would look? How is this kind of situation normally resolved i.e. a view accepts more than one dataset from the controller/model
[eluser]CroNiX[/eluser]
Ohhh I see the problem. In your controller, you are: Code: $listmobiles['country'] = $this->htc_model->GetCountryList(); Code: foreach($data['country'] as $Result) { 1) there is no "data" variable. 2) you access the "country" data by using just $country, not $array_variable_that_was_sent_to_the_view['country']. When you send data to a view in an array, it runs extract() on it so you access the variables by the array key that they were stored under when sending the array to the view. So it should be: Code: foreach($country as $Result) {
[eluser]dharmy[/eluser]
Thanks - I gave that a go, but see the following error in Fiddler Code: <h4>A PHP Error was encountered</h4> The view code that causes that error is : Code: <td>
[eluser]CroNiX[/eluser]
I'm not seeing an immediate problem. In your controller, after you put the county and mobile results into the $listmobiles array, dump that array and see if the data is in the correct format. I don't understand why your loop was initially working correctly when you were using $data['country'] to begin with because the way you have it now should work and the way you had it originally shouldn't!
[eluser]dharmy[/eluser]
Yes it is odd... I did a var_dump() but only got the country's array not the 2nd one... Well either that or its not dumping everything to screen... Any other dump functions I can try?
[eluser]CroNiX[/eluser]
If you aren't getting the data back for that one, check the model. Maybe the query is bad.
[eluser]InsiteFX[/eluser]
He maybe returning an array when he should be returning an object. What are you returning for these two methods in your model? Code: $this->htc_model->GetCountryList();
[eluser]dharmy[/eluser]
Hi there This is the function returning the data from the model: Code: function GetMobiles() |
Welcome Guest, Not a member yet? Register Sign In |