我正在处理视图,我想在我的视图中从数据库中打印任务ID 以下是我的控制器功能
控制器: -
function editMilestone($editid){
//, $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'];
$status_result = $this->getstatus->getEnumValues(MILESTONE, 'status');
$result = $this->milestonemodel->getEditMilestone($editid , $taskid);
$pendingbug = $this->bugmodel->getBug($id, $is_master_admin);
$pendingtask = $this->taskmodel->getTask($id, $is_master_admin);
if ($result == true) {
$session_msg_data = $this->session->userdata('msg');
if (isset($session_msg_data) && !empty($session_msg_data)) {
$milestonemsg = isset($session_msg_data['milestonemsg']) ? $session_msg_data['milestonemsg'] : '';
$milestoneopt = isset($session_msg_data['milestoneopt']) ? $session_msg_data['milestoneopt'] : '';
$this->session->unset_userdata('msg');
} else {
$milestonemsg = '';
$milestoneopt = '';
}
$data = '';
$data = array('username' => $username,
'is_master_admin' => $is_master_admin,
'imagethumb' => $imagethumb,
'result' => $result,
'taskid' => $taskid,
//'editid'=>$editid,
'status_result' => $status_result,
'profileopt' => $milestoneopt,
'profilemsg' => $milestonemsg,
'pendingtask' => $pendingtask,
'pendingbug' => $pendingbug
);
$this->load->view('milestone/edit_milestone', $data);
} else {
redirect('task', 'refresh');
}
} else {
//If no session, redirect to login page
redirect('home/logout', 'refresh');
}
}
型号: -
function getEditMilestone($id){
//, $taskid) {
$status = array(PUBLISH, UNPUBLISH, BLOCK);
$this->db->select('*');
$this->db->from(MILESTONE);
$this->db->where('id', $id);
//$this->db->where('taskid', $taskid);
$this->db->where_in('status', $status);
$this->db->limit(1);
//echo $this->db-last_query();
$query = $this->db->get();
if ($query->num_rows() == 1) {
return $query->result();
} else {
return false;
}
}
查看: - 里程碑视图
<div class="message">
<span class="arrow"></span>
<span class="body">
<?php
echo '<b> <U> Task Title </U>:- </b>  ';
echo $milestone_row->tasktitle;
echo '<br/>';
echo '<b> <U> Workspace Title </U>:- </b>  ';
echo $milestone_row->workspacetitle;
echo '<br/>';
echo '<b> <U> Description </U>:- </b>  ';
echo $milestone_row->description;
echo '<br/>';
echo '<b> <U> Hours </U>:- </b>  ';
echo $milestone_row->esthours;
echo 'hrs';
echo '<br/>';
echo '<b> <U> Minutes </U>:- </b>  ';
echo $milestone_row->estmin;
echo'mins';
echo '<br/>';
?>
<a href="<?php echo base_url(); ?>milestone/editMilestone/<?php echo $milestone_row->id;?>">Edit</a>
</div>
当我点击上面视图中的编辑链接时,它将从控制器转移到editMilestone,它将转移到另一个视图edit_milestone
查看: - edit_milestone
<?php
$attributes = array('class' => 'form-horizontal', 'id' => 'form_add_milestone');
echo form_open('milestone/validateEditMilestone/'.$result[0]->id.'/'.$taskid, $attributes);
?>
<input type="text" readonly="readonly" value="<?php echo $taskid; ?>" name="taskid" />
我想从数据库
打印我的taskid答案 0 :(得分:2)
问题在于代码。如果未在以下行中初始化,则使用$taskid
$result = $this->milestonemodel->getEditMilestone($editid , $taskid);
当您将该值放入$data
时,它不起作用,因为$taskid
中没有值
您应该在里程碑视图中将$taskid
作为参数传递,或者创建另一个查询以从db中获取它。