我有一个Flash应用程序,它使用单个php文件从数据库检索记录(使用Zend框架)。当应用程序第一次开始时,我打电话给php来设置一个类变量,以便将来对数据库的所有请求都将使用此变量根据其值选择记录。因此,这里的类是如何开始的:Zend PHP类可变保留MySQL查询
class MyClass
{
private $animal = "";
public function setAnimal($anim) {
$this->animal = $anim;
echo($this->animal); //this correctly prints the variable I passed in
}
后来,根据用户的输入,我做出此一等级不同方法的调用,但它仿佛类变量$动物已经被人遗忘,因为它没有不再有对类的任何后续访问值:
public function getAnimals()
{
echo('getAnimals: ');
echo($this->animal); //this prints nothing - as if it doesn't know what "animal" is
$result = mysql_query("SELECT * FROM animals WHERE animal='$this->animal'"); //and therefore this query doesn't work
$t = array();
while($row = mysql_fetch_assoc($result))
{
array_push($t, $row);
}
return $t;
}
所以我的问题是,我怎样才能得到一个PHP类变量坚持这样我就可以将它设置一次,我可以在任何时候访问应用程序的生命?
是的,这就是我所害怕的。看起来我必须对会话和flash进行一些研究。谢谢。 – sol 2010-01-09 22:04:10