消息:未定义变量userid,workspaceid

时间:2013-12-28 09:57:36

标签: php mysql codeigniter

我正在制作一个视图,使用文本框中的连接向我显示数据库中的数据。

现在我收到了错误:

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>

在我的View中,值是使用taskid打印; ?&GT; &安培; workspacetitle; ?&GT;在文本框上,但错误打印在页面顶部

3 个答案:

答案 0 :(得分:0)

没有为变量$userid$workspaceid

分配值
 $result = $this->milestonemodel->getMilestone($taskid, $userid, $workspaceid, $is_master_admin) ;

答案 1 :(得分:0)

您需要将$ result传递给视图。添加以下代码:

$data['result']= $result;

致电之前:

 $this->load->view('milestone/add_milestone', $data);

然后在您的视图中,将其引用为:

$result->userid;

答案 2 :(得分:0)

试试这个控制器,

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