Welcome Guest, Not a member yet? Register   Sign In
access controller variables in a model
#3

[eluser]Unknown[/eluser]
thanks but i am not sure that answer my question
here is some code to visualize what i am saying

Code:
class test extends CI_Controller {
var $ctrl_var=10;

public function index(){
  echo  $this->ctrl_var; //here display 10
  $this->load->model('test_model');
  echo  $this->ctrl_var; //here display 10
}
}

class test_model extends CI_Model{

var $my_model_var="Halo";

function __construct(){
  parent::__construct();

  echo $this->ctrl_var; //here display 10
  var_dump(isset($this->ctrl_var)); //here display bool(false) !!????
  print_r(get_defined_vars()); //here display Array ( [this] => test_model Object ( [my_model_var] => Halo ) )
  var_dump(isset($GLOBALS['CI']->ctrl_var)); // here display bool(true)

  $this->ctrl_var = 20;

  echo $this->ctrl_var; //here display 20
  var_dump(isset($this->ctrl_var)); //here display bool(true)
  print_r(get_defined_vars()); //here display Array ( [this] => test_model Object ( [my_model_var] => Halo [ctrl_var] => 20 ) )
}
}

if you meant that my ctrl_var inside the model is only a reference to the controller's variable , so i believe that modifying it in the model would also modify it in the controller.
and also i believe that isset an existing reference return true
???


Messages In This Thread
access controller variables in a model - by El Forum - 02-07-2012, 08:33 AM
access controller variables in a model - by El Forum - 02-07-2012, 01:38 PM
access controller variables in a model - by El Forum - 02-08-2012, 08:42 AM
access controller variables in a model - by El Forum - 08-21-2012, 12:57 PM
access controller variables in a model - by El Forum - 08-21-2012, 02:54 PM



Theme © iAndrew 2016 - Forum software by © MyBB