Variable not being passed |
[eluser]Booster77[/eluser]
Hello everyone, I'm staring myself blind at my code at the moment. I have succesfully implemented this method before but somehow it won't work now. I'm trying to get a versionnumber out of my database and display it in the footer. But whatever I try it will not pass the variable to the view. I've literally copied the code from a working version I have on another page. I'm hoping I'm looking over something really simple. To make it easier to spot I've replaced the function for a static value, but that also doesn't work. Can you please look at my code and see what I'm doing wrong? Thank you so much in advance My model (which in this example is not being used but is being called so I've included it for you): Code: <?PHP My controller: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); My view: Code: <FOOTER> The error I keep getting (wether I try print_r($test); or echo $test; ) is Undefined variable: test
[eluser]Tpojka[/eluser]
Check views again. You should add the key to your $data variable because using as is, it is CI native engine (as you calling it after view 'footer'). Your key should be unique value that can be called in view as required. Something like: Code: // controller Code: // view
[eluser]Tpojka[/eluser]
I made mistake above. This is how it should be used. In view you would call it as variable: Code: // view
[eluser]Booster77[/eluser]
I'm sorry, I was too soon to celebrate. I literally copied your code, to make sure I did nothing wrong and I get the same error: Message: Undefined variable: myKey
[eluser]Booster77[/eluser]
Ok I think I found out what my problem is. I load footer through another controller. So in another controller I say load header, main and footer. So although the data is being transported, it transport it to that controller and THEN it loads my footercontroller. So I obviously need to build this part in the first controller and not the footer. I found out by loading the footer view directly. Thank you so much for helping!
[eluser]InsiteFX[/eluser]
When you are having problems sending $data to your views you can always do this which will make them global to all of your views Code: $data = array();
[eluser]Booster77[/eluser]
That is also very helpful information! Thank you so much.
|
Welcome Guest, Not a member yet? Register Sign In |