nemo
(Nemoneel)
April 21, 2010, 7:06pm
1
Hey Guys,
I have a silly question, I have two models like this
public function user()
{
$name = "test";
}
public function call()
{
I want to call $name variable here. is that possible? I really appreciate if anyone can help me how to solve this nobis question…
}
kevinkorb
(Korb Kevin)
April 21, 2010, 7:35pm
2
I see you have two methods there. you have defined $name as a local variable in your user method so it will not be available to the call method.
You could do:
class myModal {
protected $name;
public function user() {
$this->name = "my name";
}
public function call() {
return $this->name;
}
}
nemo
(Nemoneel)
April 21, 2010, 7:55pm
3
kevinkorb:
I see you have two methods there. you have defined $name as a local variable in your user method so it will not be available to the call method.
You could do:
class myModal {
protected $name;
public function user() {
$this->name = "my name";
}
public function call() {
return $this->name;
}
}
Still have problem. Here is my code
protected $A;
protected $B;
public $name = "abc";
public function ret()
{
$A = ‘this is test’;
$B = ‘this is test1’;
}
public function retrieve()
{
$this->C = $this->A .$name. $this->B;
}
yoshi
(Jaschakoch)
April 21, 2010, 10:44pm
4
Hi,
i don’t know if i understood your problem but it should be:
protected $A;
protected $B;
public $name = "abc";
public function ret()
{
$this->A = 'this is test';
$this->B = 'this is test1';
}
public function retrieve()
{
$this->C = $this->A .$this->name. $this->B; //btw. there is no $C?!
}
Regards