Yii Framework Forum: model problem - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

model problem Rate Topic: -----

#1 User is offline   nemo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 24-February 10

Posted 21 April 2010 - 02:06 PM

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.....
}
0

#2 User is offline   kevinkorb 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 17-April 09
  • Location:Saint Louis

Posted 21 April 2010 - 02:35 PM

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;
}
}

0

#3 User is offline   nemo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 24-February 10

Posted 21 April 2010 - 02:55 PM

View Postkevinkorb, on 21 April 2010 - 02:35 PM, said:

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;
}
0

#4 User is offline   yoshi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 28-February 09
  • Location:Germany

Posted 21 April 2010 - 05:44 PM

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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users