i have a controller with multiple functions that have a variable inside them. I would like to access those variables from another function. Any ideas?
class RoomsContr开发者_如何学编程oller extends AppController {
public $helpers = array('Js' => 'Jquery');
public $components = array('RequestHandler');
function test1(){
$balcony = $_REQUEST['qwe'];
$this->set('qwe',$qwe);
}
function test2() {
$occy = $_REQUEST['wer'];
$this->set('wer',$wer);
}
function test3() {
$deck = $_REQUEST['ert'];
$this->set('ert',$ert);
}
function success() {
// i want to use $qwe, $wer and $ert here
}
any ideas on how to do this? do i have to set up global variables public $qwe;
?
thanks
You can create controller properties but it will break the design of the framework, so I suggest using Configuration class for this purpose, you can store variable values and retrieve using this class, here's a documentation:
http://book.cakephp.org/view/42/The-Configuration-Class
You can store variables in Session if you need their values after redirect:
$this -> Session -> write("variable", "value");
and retrieve:
$this -> Session -> read("variable");
You can do with the use of CakePHP session
$this->Session->write('qwe', $qwe);\\ in test1
$qwe= $this->Session->read('qwe'); \\ in sucess
http://book.cakephp.org/view/1312/write
Though there are many mistake's and ambiguity in the code.
function test1(){
$balcony = $_REQUEST['qwe'];
$this->set('qwe',$qwe);
}
Here you are taking request value in $balcony
while you setting qwe with $qwe
. And you are doing same thing in all function, I think you have to check this out.
Also as deceze
said you are not using the flow of success function properly.
精彩评论