如何修复警告:在 php 本机 MVC 中为 foreach() 提供的参数无效



我已经构建了一个简单的应用程序,用于在java eclipse中使用调用休息服务查看表上的数据,在php本机mvc中使用curl,我试图调用休息服务使用curl但在表中显示消息错误,我该如何解决?我将感谢您的帮助:)(

这是我在 PHP 中的控制器

<?php
class App_UserManagement_Control_UserManagement extends UserControl{
public function usermanagement(){
Template::setTitle('User Management');
$result = $this->getUser();      
$dataresult = json_decode($result, true);
if($dataresult === NULL) {
echo "<script language = "javascript">window.alert("Tidak Ada Data");";
echo "javascript:history.back();</script>";
return false;
}
$data['user'] = $dataresult;
return $data;
}
public function getUser(){
Template::setTitle('User Management');
$user_comp_code = Session::get('pyrCode');
/*API URL */
$url = "http://localhost:8585/usermaster/$user_comp_code";
/*init cURL resource */
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPGET, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec ($curl);
//echo $url;echo $result;  die;
if ($result === FALSE){
die('Curl failed: ' . curl_error($curl));
}
curl_close($curl);
return $result;
} 

这是我在 html 中的代码

<?php
$main_controll = new App_UserManagement_Control_UserManagement();
$data_from_ctr = $main_controll->usermanagement();
?>
<table cellspacing="2" cellpadding="2" border="0" align="left" id="tablecontent">                      
<thead style="background-color:#eee;">
<th width="25">#</th>
<th width="80">Username</th>
<th width="117">Name</th>
<th width="117">Company Code</th>
<th width="117">Company Name</th>
<th width="80">User Access</th>
<th width="80">Login Status</th>
<th width="80">User Status</th>
<th width="200">Action</th>
</thead>
<tbody>
<?php if($dataresult == NULL): ?>
<?php $i = 1; foreach ($dataresult as $row): ?>
<tr>
<td><?php echo $i++; ?></td>
<td><?php echo $row ['_user'] ?></td>
<td><?php echo $row ['_fullName'] ?></td>
<td><?php echo $row ['_pyrCode'] ?></td>
<td><?php echo $row ['_desc'] ?></td>
<td><?php echo $row ['group_user'] ?></td>
<td><?php echo $row ['_status'] ?></td>
<td><?php echo $row ['Active'] ?></td>
<td></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</fieldset>  

这是我的消息错误

Warning: Invalid argument supplied for foreach() 
if($dataresult == NULL)

看起来不对劲。不应该是:

if($dataresult !== NULL)

?你不能循环通过空!

但这还不是全部。你用你的内部循环覆盖$row

<?php $i = 1; foreach ($dataresult as $row): ?>
$No=0;
foreach($data_from_ctr['user'] as $row) {

相关内容

  • 没有找到相关文章

最新更新