Welcome Guest, Not a member yet? Register   Sign In
passing array to views
#7

[eluser]vitoco[/eluser]
[quote author="SardiorDragon" date="1246297704"]This can be done in the view but as a personal preference I would rather check the array in the controller and if it is FALSE then pass an empty array to the view. This way the foreach will still find an array but will not actually do anything because there is no data to handle.[/quote]

true, if you pass an empty array, the code will look like this.

Code:
<?
    // IN THE CONTROLLER
    $path   = base_url().'/images/';
    $images = get_filenames($path,TRUE) ;
    $data['images'] = ( is_array( $images ) ) ? $images : array() ;

    // IN THE VIEW
    if( count( $images ) > 0 )
    {
        //<pre> tag it's only to make the array structure more readeable
        echo '<pre>'.print_r( $images , true ) .'</pre>';
    }
    else
    {
        echo 'NO IMAGES ( EMPTY ARRAY ) ';
    }
?&gt;


Messages In This Thread
passing array to views - by El Forum - 06-27-2009, 03:44 PM
passing array to views - by El Forum - 06-27-2009, 03:56 PM
passing array to views - by El Forum - 06-27-2009, 03:58 PM
passing array to views - by El Forum - 06-27-2009, 09:40 PM
passing array to views - by El Forum - 06-28-2009, 06:34 PM
passing array to views - by El Forum - 06-29-2009, 06:48 AM
passing array to views - by El Forum - 06-29-2009, 09:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB