我正在视图中工作,我想从数据库中打印任务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;
        }
    }


VIEW:-里程碑视图

<div class="message">
                <span class="arrow"></span>
                <span class="body">
                    <?php
                    echo '<b> <U> Task Title </U>:- </b> &nbsp';
                    echo $milestone_row->tasktitle;
                    echo '<br/>';
                    echo '<b> <U> Workspace Title </U>:- </b> &nbsp';
                    echo $milestone_row->workspacetitle;
                    echo '<br/>';
                    echo '<b> <U> Description </U>:- </b> &nbsp';
                    echo $milestone_row->description;
                    echo '<br/>';
                    echo '<b> <U> Hours </U>:- </b> &nbsp';
                    echo $milestone_row->esthours;
                    echo 'hrs';
                    echo '<br/>';
                    echo '<b> <U> Minutes </U>:- </b> &nbsp';
                    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

最佳答案

问题出在代码上。您正在使用$taskid时未在下一行中对其进行初始化,

$result = $this->milestonemodel->getEditMilestone($editid , $taskid);
而当您将该值放在$data中时,它将不起作用,因为$taskid中没有任何值
您应在里程碑视图中将$taskid作为参数传递,或创建另一个查询以从数据库中获取它。

关于php - View 中 undefined variable taskid,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20966115/

10-12 19:56