CodeIgniter Forums
'Array" showing up all over my app - 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: 'Array" showing up all over my app (/showthread.php?tid=2021)



'Array" showing up all over my app - El Forum - 07-12-2007

[eluser]Chad Crowell[/eluser]
http://rj.webinception.com/index.php/sell

Notice at the top of the form the word Array? Also it shows up im my header in several places.

Anyone know why??

Here is the code that starts the form:
Code:
<?=$attributes = array('class' => 'form', 'id' => 'sellform');
echo form_open('sell/images', $attributes);?>

And the search area of the header:
Code:
<?=$attributes = array('class' => 'form', 'id' => 'searchform');
                echo form_open('search', $attributes);?>
                Search
                <?=$data = array(
                  'name'        => 'txtsearch',
                  'id'          => 'txtsearch',
                  'value'       => '',
                  'maxlength'   => '',
                  'size'        => '',
                  'style'       => '',
                );                
                echo form_input($data);?>

                <?=$options = array(
                    ''      => 'In All Categories',
                    #foreach($categories as $category):
                    #    $category->shortname    => $category->category_name,;
                    #endforeach;
                );
                echo form_dropdown('searchcat', $options);?>

                <?echo form_close();?>

Why does CI keep printing out the word 'Array'?


'Array" showing up all over my app - El Forum - 07-12-2007

[eluser]PsyCow[/eluser]
PHP short tags return your $data array.

Try this :
Code:
<?php $attributes = array('class' => 'form', 'id' => 'sellform');
echo form_open('sell/images', $attributes); ?>
And again for your next snippet.

PHP short tags "<?=$var?>" is equal to "<?php echo $var; ?>".
So when you use it to set your variables $attributes, $data, and $options, it will return the array and so print 'Array' on your page.


'Array" showing up all over my app - El Forum - 07-12-2007

[eluser]coolfactor[/eluser]
Code:
'style' => '',
...
''      => 'In All Categories',

The last element in an array should not be followed by a comma.


'Array" showing up all over my app - El Forum - 07-12-2007

[eluser]Bulk[/eluser]
[quote author="coolfactor" date="1184243549"]
Code:
'style' => '',
...
''      => 'In All Categories',

The last element in an array should not be followed by a comma.[/quote]

IMO Only for style reasons - PHP has never thrown an error for that reason for me...


'Array" showing up all over my app - El Forum - 07-12-2007

[eluser]coolfactor[/eluser]
Okay, my servers don't like it. Must be a different error threshold.


'Array" showing up all over my app - El Forum - 07-12-2007

[eluser]Bulk[/eluser]
Really? :o what error level are you set at? In my dev enviroment I though it was showing everything...


'Array" showing up all over my app - El Forum - 07-12-2007

[eluser]coolfactor[/eluser]
Actually, I think you're right. I'm not getting any errors. I must've been thinking about Javascript, which doesn't like that.


'Array" showing up all over my app - El Forum - 07-12-2007

[eluser]Bulk[/eluser]
Ah yeah thats true, IE goes nuts if you do that Sad


'Array" showing up all over my app - El Forum - 07-12-2007

[eluser]Chad Crowell[/eluser]
CF I generally do it that way, but I noticed in the CI user guide that they do include trailing commas, so I don't go out of my way to avoid them.