我正在使用一个视图,该视图使用文本框中的联接向我显示数据库中的数据。
现在我得到了错误:
Message: Undefined variable: userid
Message: Undefined variable: workspaceid
以下是我的模型,视图和控制器
型号:-
function getMilestone($taskid, $userid,$workspaceid, $is_master_admin) {
$this->load->database();
if($is_master_admin) {
$this->db->select('user.title as usertitle, workspace.title as workspacetitle,workspace.id as workspaceid,task.title as tasktitle,task.id as taskid, milestone.*');//task.title as tasktitle,task.id as taskid,
} else {
$this->db->select('*');
}
$this->db->from(MILESTONE);
if($is_master_admin) {
$this->db->join(USER, 'milestone.userid = user.id', 'inner');
$this->db->join(WORKSPACE, 'workspace.id = milestone.workspaceid','inner');
$this->db->join(TASK, 'task.id = milestone.taskid', 'inner');
} else {
}
$this->db->where('taskid', $taskid);
if($is_master_admin) {
$this->db->order_by("userid", "asc");
} else {
$this->db->where('userid', $userid);
}
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result();
} else {
return false;
}
}
控制器:-
function addNew($taskid) {
if ($this->session->userdata('logged_in')) {
$session_data = $this->session->userdata('logged_in');
$id = $session_data['id'];
$username = $session_data['username'];
$is_master_admin = $session_data['master'];
$imagethumb = $session_data['imagethumb'];
$pendingbug = $this->bugmodel->getBug($id,$is_master_admin);
$pendingtask = $this->taskmodel->getTask($id,$is_master_admin);
$status_result = $this->getstatus->getEnumValues(MILESTONE,'status');
$result = $this->milestonemodel->getMilestone($taskid, $userid, $workspaceid, $is_master_admin) ;
$data='';
$data = array('username' => $username,
'is_master_admin' => $is_master_admin,
'imagethumb' => $imagethumb,
'result' => $result,
'status_result' => $status_result,
'taskid' => $taskid,
'pendingtask' => $pendingtask,
'pendingbug' => $pendingbug
);
$this->load->view('milestone/add_milestone', $data);
} else {
//If no session, redirect to login page
redirect('login', 'refresh');
}
}
查看:-
<div class="control-group">
<label class="control-label">Title<span class="required">*</span></label>
<div class="controls">
<input type="text" name="title" data-required="1" class="span6 m-wrap" readonly="readonly"value="<?php echo $result[0]->taskid; ?>"/> <p><?php echo form_error('title'); ?></p>
<input type="hidden" id="tasktype" name="tasktype" data-required="1" class="span2 m-wrap" value="<?php //echo $task_type ?>"/>
</div>
</div>
<div class="control-group">
<label class="control-label">Workspace</label>
<div class="controls">
<input type="text" readonly="readonly" value="<?php echo $result[0]->workspacetitle; ?>"></input>
</div>
</div>
在我看来,值是使用taskid进行打印; ?>&工作区标题; ?>在文本框中,但错误打印在页面顶部
最佳答案
试试这个控制器,
function addNew($taskid) {
if ($this->session->userdata('logged_in')) {
$session_data = $this->session->userdata('logged_in');
$id = $session_data['id'];
$username = $session_data['username'];
$is_master_admin = $session_data['master'];
$imagethumb = $session_data['imagethumb'];
$pendingbug = $this->bugmodel->getBug($id, $is_master_admin);
$pendingtask = $this->taskmodel->getTask($id, $is_master_admin);
$status_result = $this->getstatus->getEnumValues(MILESTONE, 'status');
$result = $this->milestonemodel->getMilestone($taskid, $username, $id, $is_master_admin);
$data = '';
$data = array('username' => $username,
'is_master_admin' => $is_master_admin,
'imagethumb' => $imagethumb,
'result' => $result,
'status_result' => $status_result,
'taskid' => $taskid,
'pendingtask' => $pendingtask,
'pendingbug' => $pendingbug
);
$this->load->view('milestone/add_milestone', $data);
} else {
//If no session, redirect to login page
redirect('login', 'refresh');
}
}
我认为$ userid和$ workspace是$ username和$ id
关于php - 消息: undefined variable 用户标识,工作区标识,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20813214/