未定义的变量:BODY

时间:2017-07-24 09:53:08

标签: php codeigniter

我有一个php错误:

  • 严重程度:通知
  • 消息:未定义的变量:BODY
  • 文件名: models / projects_model.php
  • 行号: 232

我不明白为什么变量$BODY未定义。你能解释一下吗? 这是我的projects_model文件:

    private function Modal()
    {
        include APPPATH."language/".LANG.".php";

        $ProjectId = htmlspecialchars($_POST['modal'],ENT_QUOTES);
        $getProject = $this->db->query("SELECT `projectName`,`managerId` FROM `projects` WHERE `projectId`='$ProjectId'");
        if ($getProject->num_rows()>0)
        {
            $project = $getProject->row_array();

            $getUsers = $this->db->query("SELECT * FROM `usertoproject` WHERE `projectId`='$ProjectId' AND `isEnabled`='1'");
            if ($getUsers->num_rows()>0)
            {
                $BODY=''; $line = "";
                foreach ($getUsers->result_array() as $row){
                    $line.=$row['userId'].",";
                    $Post = '';
                    if ($row['isEnabled']==1) $checked = ' checked'; else $checked = '';
                    $getUser = $this->db->query("SELECT `userName` FROM `users` WHERE `userId`='".$row['userId']."'");
                    if ($getUser->num_rows==1)
                    {   
                        if (!empty($row['postId']))
                        {
                            $explodePost = explode(',',$row['postId']);
                            for($p=0;$p<count($explodePost);$p++)
                            {
                                $getPost = $this->db->query("SELECT `postName` FROM `posts` WHERE `projectId`='$ProjectId' AND `postId`='".$explodePost[$p]."'");
                                if ($getPost->num_rows()>0)
                                {
                                    $PostName = $getPost->row_array();
                                    $Post.= $PostName['postName'].', ';
                                }
                            }
                            $Post = mb_substr($Post,0,mb_strlen($Post,"UTF-8")-2,"UTF-8");
                        }
                        $User = $getUser->row_array();
                        $ex = explode(",",$project['managerId']);
                        if (in_array($row['userId'],$ex)) $Post.='<b> '.$LANGUAGE['Manager'].'</b>';

                        $BODY = '<table style="margin-top:1em;margin-bottom:1em;width:100%" id="user'.$row['UTPId'].'">
                        <tr>
                        <td><input type="checkbox" id="check'.$row['UTPId'].'"'.$checked.' onclick="EnableUser('.$row['UTPId'].')"> '.$User['userName'].' <font style="color:#666">('.$Post.')</font></td><td style="text-align:right;margin-right:0.2em">                       
<button type="button" onclick=Delete('.$row['UTPId'].',"usertoproject","UTPId") class="btn btn-danger"><i class="fa fa-trash" aria-hidden="true"></i></button> 
<button type="button" onclick="EditUserToProject('.$row['UTPId'].')" class="btn btn-default"><i class="fa fa-pencil" aria-hidden="true"></i></button><br></td>
</tr></table>';
                    }
                }
            }
            $event = 'event,"user","user",'.$ProjectId;
            echo '<div class="modal-content"><div class="modal-header">
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              <h4 class="modal-title">'.$project['projectName'].'</h4>
            </div>
            <div class="modal-body">
            <input type="text" class="form-control" id="user-search" placeholder="'.$LANGUAGE['SearchPhrase'].'" onchange=Search("user","user",'.$ProjectId.') onkeypress=runScript('.$event.')>
<div style="text-align:center">
<button type="button" class="btn btn-info" onclick=Search("user","user",'.$ProjectId.')>
      <span class="glyphicon glyphicon-search"></span> '.$LANGUAGE['Search'].'</button>
</div>
<div id="user_result">
*232 line:*'.$BODY.'
            </div>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">'.$LANGUAGE['Close'].'</button>
            </div>
          </div>
          <script>
          var options2 = {
    url: function(phrase) {
        return "'.SITEURL.'/'.LANG.'/find/?user="+encodeURIComponent(phrase);
    },
    getValue: "userName"
};

$("#user-search").easyAutocomplete(options2);

          </script>
          ';
        }else echo $this->db->error();
        exit;
    }

1 个答案:

答案 0 :(得分:2)

@Ksenia if($ getUsers-&gt; num_rows()&gt; 0)首先检查此条件是否为真,否则在此条件之前声明$ BODY变量