codeigniterビューでドロップダウンリストにfirstnameとlastnameを表示できません。今は空白のドロップダウンを表示しています。参照のために添付されたMVCコード。モデルは正しいデータを返しています。つまり、このprint_r($ data ['groups'])を実行しようとしたときです。 ダイ;私のコントローラでは以下のように出力しますcodeigniterのドロップダウンとして多次元配列から返された値を出力しようとしています
Array ([0] => Array ([id] => 62 [userid] => 67 [emp_code] => 050 [emp_shift] => General Shift [emp_category] => Full Time [cccode] => [prefix] => Mr. [firstname] => Divya [middlename] => [lastname] => Darshini [designation_id] => 9 [division_id] => [branch_id] => 5 [company] => [email] => [email protected] [personal_email] => [nickname] => [url] => [birthday] => 23-09-1990 [panno] => [passportno] => [passportdate] => [joining_date] => 08-07-2016 [resignation_date] => [team_id] => [tag_ids] => [im] => [facebook] => [twitter_handle] => [linkedin_id] => [instagram] => [googleplus] => [maidenname] => [profileimage] => [blood_group] => B Positive [gender] => Female [married] => [anniversary] => 01-01-1970 [ctc] => [mood] => [doc_type] => [org_to] => [org_from] => [org] => [role_title] => [org_skills] => [scanned_doc_work] => [pass_year] => [adm_year] => [degree] => [univ] => [edu_scanned_doc] => [declare_home] => [declare_menu1] => [declare_family] => [declare_menu4] => [declare_menu7] => [declare_menu8] => [declare_menu2] => [declare_menu3] => [s_cluster_id] => 1 [status] => 1 [deleted] => 0 [registrationtime] => 1466579573 [timemodified] => 0 [modifierid] => 0 [alternate_email] => [notice_period] => 0))
私はドロップダウン値としてファーストネームとラストネームを印刷しようとしています。
マイビューコードは:
<table>
<tr>
<td>
Name
</td>
<td>
<select class="form-control" name="name">
<?php
foreach($groups as $row){
echo '<option value="'.$row->firstname.'">'.$row->firstname.' '.$row->lastname.'</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td>
Exit Type
</td>
<td>
<select class="form-control" id="security_question_1" name="exit_type">
<option name="exit_type" value="" selected>Select a option</option>
<option name="exit_type" value="Absconding">Absconding</option>
</select>
</td>
</tr>
<tr></tr>
<tr>
<td>
<label>Absconding Since</label>
</td>
<td>
<div class="date" data-date="12-02-2012" data-date-format="mm-dd-yyyy" data-date-viewmode="years">
<input placeholder="Absconding Since" class=" m-wrap col-md-8 form-control " id="enddt" type="text" name="abscondingsince" value="<?php if($row->requested_date!='') echo date("d-m-Y",$row->requested_date); ?>" required/>
</td>
</tr>
<tr>
<td>
<label>Date of contact via Phone</label>
</td>
<td>
<div class="date" data-date="12-02-2012" data-date-format="mm-dd-yyyy" data-date-viewmode="years">
<input placeholder="Date of contact via Phone" class=" m-wrap col-md-8 form-control " id="enddtt" type="text" name="dateofcontactviaphone" value="<?php if($row->requested_date!='') echo date("d-m-Y",$row->requested_date); ?>" required/>
</td>
</tr>
<td>
<label>
Response/Outcome from attempt to contact through phone
</label>
</td>
<td>
<textarea class="form-control" name="commentsphone"></textarea>
</td>
<tr>
<td>
<label>Date of contact via email</label>
</td>
<td>
<div class="date" data-date="12-02-2012" data-date-format="mm-dd-yyyy" data-date-viewmode="years">
<input placeholder="Date of contact via email" class=" m-wrap col-md-8 form-control " id="enddttt" type="text" name="dateofcontactviaemail" value="<?php if($row->requested_date!='') echo date("d-m-Y",$row->requested_date); ?>" required/>
</td>
</tr>
<td>
<label>
Response/Outcome from attempt to contact through email
</label>
</td>
<td>
<textarea class="form-control" name="commentsemail"></textarea>
</td>
<tr>
<td>
Attach Email Sent to Employee<input multiple="multiple" name="userfile1[]" size="20" type="file" />
</td>
<td>
Attach Phone Logs made to Employee<input multiple="multiple" name="userfile2[]" size="20" type="file" />
</td>
</tr>
</tr>
</table>
マイコントローラコードがある:
function manager_add_absconding(){
global $SITE,$USER;
\t $data = array();
\t $data['row'] = new stdClass();
\t $data['row'] = $this->admin_init_elements->set_post_vals($this->input->post());
\t $data['offices']=$this->mod_common->get_all_offices();
\t $clients = currentuserclients();
\t $data['roles'] = $this->mod_common->get_cat_array('designation','status',"1' AND id > '0",'designation');
\t \t \t
\t $data['reasons'] = $this->exit_common->get_all_reasons();
\t $id = $this->uri->segment(3);
\t //$data['roles'] = $this->exit_common->get_cat_array('designation','status',"1' AND id > '0",'designation');
\t \t \t get_city_state_country_array($data,array('cityid'=>$data['row']->cityid));
$data['error_message'] = '';
\t $data['row']->id = $this->uri->segment(3);
\t $data['id'] = $this->uri->segment(3); \t \t \t
\t $data['action'] = 'add';
\t $data['heading'] = 'Add'; \t \t \t
\t $data['msg_class'] = 'sukses';
\t $data['path']=$path; \t \t
\t $post_action = $this->input->post('action');
\t if($post_action=='add' || $post_action =='update'){
\t \t $post_array = $this->input->post();
\t \t $action = ($post_action == 'add')?'inserted':'updated';
\t \t
//echo '<pre>';print_r($SITE);die;
\t \t $post_array['exit_type'] = 'Employee Initiated';
\t \t $data['managerid'] = $this->exit_common->get_managerids($id);
\t \t $data['error_message'] = $this->exit_common->add_new_absconding_alert($post_array,$action);
\t \t \t \t \t
\t if($data['error_message'] == 'Record '.$action.' successfully'){
\t \t \t $data['row'] = new stdClass();
\t \t \t $data['row']->id = $this->uri->segment(3); \t
\t \t \t $data['row']->status = 1;
\t \t }
\t }
\t $data['grievance_types'] = $this->mod_common->get_user_allowed_leaves();
\t
if($data['row']->id>0){
\t $data['action'] = 'update';
\t $data['heading'] = 'Edit';
\t $data['rows'] = $this->mod_common->get_leave_request($data['row']->id);
\t $clid = $data['row']->id; \t
\t $data['row']->id = $clid;
\t }
\t //$data['my_detail'] = $this->mod_common->get_my_details($USER->id);
\t $data['my_detail'] = $this->exit_common->get_details_profile($USER->id,'users_details','userid'); \t
\t $data['my_detail']->userdetail = $this->exit_common->get_details($USER->id,'users');
\t get_address($data['my_detail'],ADDRESS_TYPE1,$USER->id);
\t $data['cities']=$this->exit_common->get_array_frontend('city');
\t $data['notice_period']=$this->exit_common->get_notice_period($USER);
\t $data['groups'] = $this->exit_common->get_all_names_by_user($USER);
\t $this->data['maincontent'] = $this->load->view('maincontents/manager_add_new_exit', $data,true);
$this->load->view('layout', $this->data);
}
マイモデルコード:
function get_all_names_by_user($USER){
$this->db->select('g.*,firstname,lastname');
\t $this->db->from('pr_users_details as g');
\t $this->db->where('userid', $USER->id);
\t //$this->db->join($this->myTables['pr_users_details'].' as ud','ud.userid = g.userid');
\t //$this->db->join('pr_users_details as ud','ud.userid = g.userids');
\t /* \t $this->db->join($this->myTables['users_details'].' as ud','ud.userid = g.userid');
\t $this->db->join('pr_resignation_type as gt','gt.id = g.sr_type');*/
\t $query=$this->db->get(); \t
\t $return \t = $query->result_array();
\t return $return;
}
あなたは配列を渡しており、forループはオブジェクトメソッドを示しています。ビューにprint_r($ groups)を貼り付けて、 –
の空白を貼り付けてください。つまり、ページが空白の場合 – shank
与えられた答えで試してください。 –