#1 SunPSP
一个类
class content extends spController{
public function index(){
XXXXX
}
public function edit(){
xxx
}
}
首先是
public function index(){
$uuid=$this->spArgs('uuid');
$sql="SELECT storage,fields FROM {$this->prefix}common_application WHERE uuid='$uuid' LIMIT 1";
$application=spClass('spSQL')->findSql($sql);
$this->storage=$application[0][storage];
}
获取到了$this->storage
这是一个数据表名
然后我需要在
public function edit(){
$sql="SELECT * FROM {$this->prefix}
{$this->storage} WHERE uuid='$uuid'";
$this->detail=spClass('spSQL')->findSql($sql);
}
使用$this->storage与{$this->prefix}组合成一个完整的表名
昨天问过J大,说是使用构造函数来赋值然后使用
可是无论是直接__construct()还是parent::__construct()都报错
折腾了一天多还是没找到解决方法
也百度谷歌过怎么在成员函数之间传递变量,找不到解决方案
没辙又回来这里求指点
2013-03-28 20:48:27
#2 jake
再次建议有空稍微看一下PHP基础,哪怕只是看看基础语法。
class content extends spController{
function __construct(){
parent::__construct ();
///////////////
$uuid=$this->spArgs('uuid');
$sql="SELECT storage,fields FROM {$this->prefix}common_application WHERE uuid='$uuid' LIMIT 1";
$application=spClass('spSQL')->findSql($sql);
$this->storage=$application[0][storage];
///////////////
}
public function index(){
echo $this->storage;
}
public function edit(){
echo $this->storage;
}
}
或者
class content extends spController{
function getStorage(){
$uuid=$this->spArgs('uuid');
$sql="SELECT storage,fields FROM {$this->prefix}common_application WHERE uuid='$uuid' LIMIT 1";
$application=spClass('spSQL')->findSql($sql);
return $application[0][storage];
}
public function index(){
echo $this->getStorage();
}
public function edit(){
echo $this->getStorage();
}
}
2013-03-29 08:48:49