我有代码:
function Rotuse($building){
global $lang, $wg_village, $db;
$village_id=$wg_village->id;
includelang("musu");
$parse=$lang;
$rs1zn=6400;
$rs2zn=6650;
$rs3zn=5940;
$rs4zn=1340;
$parse["rs1"]=$rs1zn;
$parse["rs2"]=$rs2zn;
$parse["rs3"]=$rs3zn;
$parse["rs4"]=$rs4zn;
if(isset($_POST['uzsakyti1'])){
if($wg_village->rs1>=$rs1zn && $wg_village->rs2>=$rs2zn && $wg_village->rs3>=$rs3zn && $wg_village->rs4>=$rs4zn){
$sql="UPDATE wg_villages SET rs1=rs1-$rs1zn, rs2=rs2-$rs2zn, rs3=rs3-$rs3zn, rs4=rs4-$rs4zn WHERE id=$village_id";
$db->setQuery($sql);
$db->query();
if($db->getAffectedRows()==0)
{
globalError2("function changeRSVillage:".$sql);
}
echo ".$village_id.- .$wg_village.";
}
else{
echo "You don't have enought resources!";
}
}
$rs1azn=29700;
$rs2azn=33250;
$rs3azn=32000;
$rs4azn=6700;
$parse["rs1a"]=$rs1azn;
$parse["rs2a"]=$rs2azn;
$parse["rs3a"]=$rs3azn;
$parse["rs4a"]=$rs4azn;
$parse['id']=$building->index;
return parsetemplate(gettemplate('rotuse_body'), $parse);
}
当我按下发布按钮时,它返回空白页但功能正常,问题在这里:
echo ".$village_id.- .$wg_village.";
也许我应该添加这样的东西:
return parsetemplate(gettemplate('rotuse_body'), $parse);
我不知道我做错了什么,我的意思是功能是我想要的,但只是它返回空白页面的问题。所以,如果有人能指出我的问题在哪里会很棒!
编辑NR1: VAR DUMP OF $ village_id和$ wg_village
string(5) "80784" object(stdClass)#25 (35) { ["id"]=> string(5) "80784" ["name"]=> string(7) "NewName" ["x"]=> string(3) "-99" ["y"]=> string(3) "-14" ["kind_id"]=> string(1) "5" ["user_id"]=> string(1) "1" ["rs1"]=> int(36000) ["rs2"]=> int(36000) ["rs3"]=> int(36000) ["rs4"]=> int(36000) ["workers"]=> string(2) "51" ["troop_keep"]=> string(1) "0" ["time_update_rs1"]=> string(19) "2014-05-09 01:45:30" ["time_update_rs2"]=> string(19) "2014-05-09 01:45:30" ["time_update_rs3"]=> string(19) "2014-05-09 01:45:30" ["time_update_rs4"]=> string(19) "2014-05-09 01:45:30" ["nation_id"]=> string(1) "2" ["merchant_underaway"]=> string(1) "0" ["child_id"]=> string(0) "" ["cp"]=> string(3) "104" ["cpupdate_time"]=> string(19) "2014-05-08 21:49:55" ["krs1"]=> string(1) "1" ["krs2"]=> string(1) "1" ["krs3"]=> string(1) "1" ["krs4"]=> string(1) "1" ["faith"]=> string(1) "3" ["faith_time"]=> string(19) "2014-05-07 22:05:44" ["dateCreate_vila"]=> string(19) "2014-05-05 20:38:26" ["capa123"]=> int(36000) ["capa4"]=> int(36000) ["speedIncreaseRS1"]=> float(1000) ["speedIncreaseRS2"]=> float(600) ["speedIncreaseRS3"]=> float(800) ["speedIncreaseRS4"]=> float(1200) ["speedIncreaseRS4Real"]=> float(1149) }
编辑nr 2添加了错误:
捕获致命错误:第70行的/includes/function_troop.php中无法将类stdClass的对象转换为字符串
该行是echo ".$village_id.- .$wg_village.";
答案 0 :(得分:0)
您的$ wg_village对象就是原因。
你不能用这样的子属性回显你的对象。
解决问题的方法之一如下:
$hi->a =1;
$hi->b =3;
echo "a=".$hi->a.", b=".$hi->b;
或者如果您只想检查具有可能不良格式的对象的内容/属性:
echo print_r($hi);
更好的方法是在您的类中创建一个方法,以您想要的格式打印属性,然后您可以执行以下操作:
echo $hi->printPredifinedFormat();