![]() |
New Associative Array? - 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: New Associative Array? (/showthread.php?tid=13519) Pages:
1
2
|
New Associative Array? - El Forum - 11-25-2008 [eluser]Dr. Seuss[/eluser] I feel extremely foolish, but here goes: I want to create custom array variables. I try: Code: $scripts['includes']=array('superfish','layout', 'admin'); And then pass the variable to a view: Code: $this->load->view('common/header', $scripts); In the view I have tried both Quote:<?php ...and... Quote:<?php In both cases, I get this error message: Quote:A PHP Error was encountered Just trying not to place everything within the "$data" array; I know that this must be possible and that I am missing something simple, but I cannot figure it out after two hours of flailing...any help would be appreciated. New Associative Array? - El Forum - 11-25-2008 [eluser]xwero[/eluser] try $includes ![]() New Associative Array? - El Forum - 11-25-2008 [eluser]Dr. Seuss[/eluser] I chanced it to read: Code: <?php ...and received the following error message: Quote:A PHP Error was encountered Crazy stuff.... New Associative Array? - El Forum - 11-25-2008 [eluser]Jamie Rumbelow[/eluser] Don't call the $this->load->vars() function - CodeIgniter will do that automatically. New Associative Array? - El Forum - 11-25-2008 [eluser]Dr. Seuss[/eluser] Alright, removed the line "", so it now reads thus: Code: $scripts['includes']=array('superfish','layout', 'admin'); ..and I returned the "view" code to read: Code: <?php ...also tried: Code: <?php ...and in desperation: Code: <?php Quote:A PHP Error was encountered New Associative Array? - El Forum - 11-25-2008 [eluser]xwero[/eluser] The way load->vars or the second parameter of load->view works is you add an associate array and the key will be the name of the variable. With your example includes should be the name of the variable in your view. Maybe the error is caused by adding the array to both vars and view method. New Associative Array? - El Forum - 11-25-2008 [eluser]Dr. Seuss[/eluser] Thank you for the reply; I realize that I did not explicitly state in the previous message that I had deleted the line "$this->load->vars() function". But the error is still present even though I am only using: Code: $scripts['includes']=array('superfish','layout', 'admin'); ...and in the view: Code: <?php I still get this error: Quote:A PHP Error was encountered New Associative Array? - El Forum - 11-25-2008 [eluser]kriztofor[/eluser] $includes is not an associative array, so you can't use $key => $val. Try Code: <?php New Associative Array? - El Forum - 11-25-2008 [eluser]Dr. Seuss[/eluser] Ahhh...good catch, but when I correct to this: Code: <?php I still get these errors: Quote:A PHP Error was encountered New Associative Array? - El Forum - 11-25-2008 [eluser]simshaun[/eluser] In your view, try this before the loop and see if it is outputting the array. Code: echo var_dump($includes); If not, and there is no other code in your view or controller that would change $includes, then this basic code should work just fine: Controller -> Code: $scripts['includes'] = array('superfish', 'layout', 'admin'); View -> Code: foreach ($includes AS $val) { |