Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3280708
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:44:05+00:00 2026-05-17T19:44:05+00:00

I have the following code in a Controller: $data[‘what’] = ‘test’; $this->load->view(‘test_view’, $data); $this->load->view(‘test_view’);

  • 0

I have the following code in a Controller:

$data['what'] = 'test';
$this->load->view('test_view', $data);
$this->load->view('test_view');

View:

<?php
    echo $what;
?>

The Result when running this code is:

testtest

Shouldn’t it be simply ‘test’ because the second time I am not passing the variable $data?
How can I make CodeIgniter behave this way?

EDIT1:

I have come up with a temporary workaround for this problem:

Replace in Loader.php:

/*
* Flush the buffer... or buff the flusher?
*
* In order to permit views to be nested within
* other views, we need to flush the content back out whenever
* we are beyond the first level of output buffering so that
* it can be seen and included properly by the first included
* template and any subsequent ones. Oy!
*
*/ 

With:

 /*
 * Flush the buffer... or buff the flusher?
 *
 * In order to permit views to be nested within
 * other views, we need to flush the content back out whenever
 * we are beyond the first level of output buffering so that
 * it can be seen and included properly by the first included
 * template and any subsequent ones. Oy!
 *
 */ 

 if (is_array($_ci_vars)){
   foreach ($_ci_vars as $key12 => $value12) {
      unset($this->_ci_cached_vars[$key12]);
   }
 }

That should remove the variables from the cache after they’re done being used.

BUG REPORT: http://bitbucket.org/ellislab/codeigniter/issue/189/code-igniter-views-remember-previous

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:44:06+00:00Added an answer on May 17, 2026 at 7:44 pm

    That is interessting, I never came to use it like this but you are right it should not do this, maybe this is some caching option. In worst case you must call it like this:

    $this->load->view('test_view', '');
    

    Edit:

    I have just checked the Code Igniter code from their repository. The reason for this is that they are really caching the variables:

        /*
         * Extract and cache variables
         *
         * You can either set variables using the dedicated $this->load_vars()
         * function or via the second parameter of this function. We'll merge
         * the two types and cache them so that views that are embedded within
         * other views can have access to these variables.
         */ 
        if (is_array($_ci_vars))
        {
            $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
        }
        extract($this->_ci_cached_vars)
    

    If I understood it correctly you must do it unfortunately like this:

    $this->load->view('test_view', array('what' => ''));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have the following code in my controller: public ActionResult Details(int id) { var
I have the following code snippet. $items['A'] = Test; $items['B'] = Test; $items['C'] =
I have following Code Block Which I tried to optimize in the Optimized section
I'm trying to use opengl in C#. I have following code which fails with
I have the following code in a web.config file of the default IIS site.
I have the following code: $bind = new COM(LDAP://CN=GroupName,OU=Groups,OU=Division,DC=company,DC=local); When I execute it from
I have the following code: SELECT <column>, count(*) FROM <table> GROUP BY <column> HAVING
I have the following code: String inputFile = somefile.txt; FileInputStream in = new FileInputStream(inputFile);
I have the following code: ListBox.DataSource = DataSet.Tables(table_name).Select(some_criteria = match) ListBox.DisplayMember = name The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.