I'm working on a project. Here's my code :
Controller
public function __construct(){
parent::__construct();
$x = $this->input->get('x');
$this->model->val = $this->model->checkval($x);
}
public function save(){
// some code to input to database
echo $this->model->val;
}
Model
public function checkval($x){
switch($x){
case 1 : $y = 10; break;
case 2 : $y = 20; break;
case 3 : $y = 30; break;
}
return $y;
}
(That's the simple version)
Message : Undefined variable: y
Filename : models/Test_model.php
I want to access save(), and it will process the $this->model->val ($this->model->val has been declared as public $val in Model). $this->model->val is get from $this->model->checkval($x) where $x is get from GET method. But, it shows this error. What did I do wrong?
$_REQUEST['x']in constructor