Welcome Guest, Not a member yet? Register   Sign In
Variable Scope
#1

Hi,

Can someone confirm that variables passed to a top view are available to a lower-down view?

e.g.

PHP Code:
$this->load->view('view1'$view1array);
$this->load->view('view2'$view2array); 

If I have a variable $test1 in $view1array, it will be available in view2?

If this is the case, is there a way/method to isolate the variables in $view1array from view2?
Reply
#2

The CI Loader handles the variables in the view:


PHP Code:
    /**
     * Set Variables
     *
     * Once variables are set they become available within
     * the controller class and its "view" files.
     *
     * @param    array|object|string    $vars
     *                    An associative array or object containing values
     *                    to be set, or a value's name if string
     * @param     string    $val    Value to set, only used if $vars is a string
     * @return    object
     */
    
public function vars($vars$val '')

    
/**
     * Clear Cached Variables
     *
     * Clears the cached variables.
     *
     * @return    CI_Loader
     */
    
public function clear_vars()

    
/**
     * Get Variable
     *
     * Check if a variable is set and retrieve it.
     *
     * @param    string    $key    Variable name
     * @return    mixed    The variable or NULL if not found
     */
    
public function get_var($key)

    
/**
     * Get Variables
     *
     * Retrieves all loaded variables.
     *
     * @return    array
     */
    
public function get_vars() 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB