Trouble with system vars - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Trouble with system vars (/showthread.php?tid=23011) |
Trouble with system vars - El Forum - 09-26-2009 [eluser]The Beginner[/eluser] Hi all, I am having a great deal of difficulty with my first major CI app. I have posted on a couple of other topics and got a lot of help. The problem i am having nos is $base_url() is not available in my views. It was when i started and then for seamingly no reason I started getting errors because I could no longer see or get $base_url(); also I cannot pass $data from one view to another. I got around the $base_url thing by defining a constant with the current base_url but I still need to figure out why it is not available and I think when I get that I will get the $data passing again. I have tried all the obvious stuff like config['base_url'] = in config.php. Anyone have any ideas. Thanks, Del :-S Trouble with system vars - El Forum - 09-26-2009 [eluser]jedd[/eluser] Is the URL helper definitely loaded? Does it work from within a controller? Do other functions from the URL helper work? Trouble with system vars - El Forum - 09-26-2009 [eluser]The Beginner[/eluser] Thanks for the reply. I wnet back and checked to see if other functions from the url helper were available and I called "current_url()"; just like that and it worked. I tried base_url(); again and it worked. I guess I ahve been placing a $ in front of it when I should not. Shows how much i know about PHP. I still have the problem of data not passing to a view. I have in my views folder a file called Container.php and in it I have the following..: Code: <html> A PHP Error was encountered Severity: Notice Message: Undefined variable: my_menu Filename: views/wpMenu.php Line Number: 7 In the controller they both have $data passed as a paramiter, so I am really confiused as to why it fails to pass the data. Any Ideas? Thanks, Del Trouble with system vars - El Forum - 09-27-2009 [eluser]jedd[/eluser] Yeah, this stuff is fairly well explained in the documentation, and again in the oodles of tutorials. The way you're doing this is a bit confusing, to my mind. Calling views within views is not something that sits well with me. Check out [url="http://codeigniter.com/wiki/Header_and_Footer_and_Menu_on_every_page_-_jedd/"]this page[/url] in the wiki - it's how I repeat lumps of code throughout my site, but in passing it'll show you another way you can do this - by calling view partials and storing the results into a variable. Knowing both approaches means you can work out what way sits better with the way you work/think. In any case, you still need to put variables into an array, and call that with your view loads - even if you're loading that view from within another view. You can look at load_vars() (?) - which will get this stuff everywhere for you, as an alternative, and might work better for you if you stick with the hierarchical view-within-a-view method. Trouble with system vars - El Forum - 09-27-2009 [eluser]The Beginner[/eluser] Hi Jedd, Thanks for the helpful information. I tried the template and it worked great when I created the simple about view shown in the instructions. When i tried a view that needed data passed to it I got the same error I had before, $header_logo not defined. I think I have some fundimintal setup problem, maybe with my server, although I uploaded it to my remote site and got the same error. It seams like anytime I try to pass data to a view it just does not happen. Any suggestions would be greatly appreciated. Thanks, Del Trouble with system vars - El Forum - 09-27-2009 [eluser]steelaz[/eluser] I assume you have variable $my_menu in views/wpMenu.php line 7. In your controller, do this: Code: // Pass $my_menu var to wpMenu view and load it into $wpMenu_view var In your main template: Code: <html> Trouble with system vars - El Forum - 09-27-2009 [eluser]jedd[/eluser] [quote author="The Beginner" date="1254085721"] Thanks for the helpful information. I tried the template and it worked great when I created the simple about view shown in the instructions. When i tried a view that needed data passed to it I got the same error I had before, $header_logo not defined. [/quote] Show the code sections for: o controller, where you set your header_logo variable, o controller, where you call the view, o view, where you use the header_logo variable. Trouble with system vars - El Forum - 09-27-2009 [eluser]The Beginner[/eluser] Quote:Show the code sections for: Ok, first the controller loading data: Code: $this->db->where('wp_header_active', '1'); This is my template.php, the plan is to load my header view, menu view contents and then my footer. Code: <html> Now the view: Code: <?php And that is it...... the error I get is : A PHP Error was encountered Severity: Notice Message: Undefined variable: header_logo Filename: views/wpHeader.php Line Number: 2 Trouble with system vars - El Forum - 09-29-2009 [eluser]jedd[/eluser] Quote: Oh, if you're using a template library now, I can't help you - never used them, and don't know how they work. Maybe changing the post subject to something about templates, rather than system variables, might attract the attention of template users. |