我在codeigniter中使用my model / Master.php的代码存在问题。
Here is screenshot of my view
模型/ Master.php:
function get_tasks($limit=20,$task_id=0,$page_num=1,$search='',$sortfield='default',$sort='sort')
{
$data = array();
$sortable_fields = array('id'=>'t.id','ime'=>'t.ime','sn_br'=>'t.sn_br','gar_stanje'=>'t.gar_stanje','opis_kvara'=>'t.opis_kvara','comment'=>'t.comment','task_assigned'=>'t.task_assigned','ime'=>'t.ime','prezime'=>'t.prezime','br_tel'=>'t.br_tel','email'=>'t.email','datum'=>'t.datum','account_id'=>'u3.account_id');
$account_id = $this->session->userdata('account_id');
$offset = ($page_num==1) ? 0 : ($page_num*$limit)-$limit;
if ($task_id!=0){
$this->db->select('t.id, t.ime, t.sn_br, t.gar_stanje, t.opis_kvara, t.comment, u2.user_firstname as task_assigned, t.ime, t.prezime, t.br_tel, t.email, t.datum, u3.account_id');
}else{
$this->db->select('SQL_CALC_FOUND_ROWS t.id, t.ime, t.sn_br, t.gar_stanje, t.opis_kvara, t.comment, u2.user_firstname as task_assigned, t.ime, t.prezime, t.br_tel, t.email, t.datum, u3.account_id', FALSE);
}
if ($task_id!=0){
$this->db->where('t.id',(string)$task_id);
}
$this->db->where('u3.account_id',(string)$account_id);
$this->db->where('t.task_status','1');
$this->db->from('serv t');
$this->db->join('users u2', 't.task_assigned = u2.user_id', 'inner');
$this->db->join('accounts u3', 'u3.account_id = u3.account_id', 'inner');
if ($task_id!=0){
$this->db->limit(1);
}else{
$this->db->limit($limit,$offset);
}
if (array_key_exists($sortfield,$sortable_fields) && ($sort=='asc' || $sort=='desc')){
$this->db->order_by($sortable_fields[$sortfield],strtoupper($sort));
}else{
$this->db->order_by('t.task_status ASC, t.datum DESC');
}
$query = $this->db->get();
// echo $this->db->last_query();
if ($query->num_rows()>0){
$tasks = $query->result_array();
if ($task_id!=0){
$data['task'] = $tasks[0];
}else{
$data['serviss'] = $tasks;
}
$query = $this->db->query('SELECT FOUND_ROWS() AS `Count`');
$data["total_rows"] = $query->row()->Count;
}else{
$data['serviss']['id'] = 'Unable to find!';
$data['serviss']['ime'] = 'Unable to find!';
$data['serviss']['prezime'] = 'Unable to find!';
$data['serviss']['br_tel'] = 'Unable to find!';
$data['serviss']['naziv_artikla'] = 'Unable to find!';
$data['serviss']['sn_br'] = 'Unable to find!';
$data['serviss']['gar_stanje'] = 'Unable to find!';
$data['serviss']['opis_kvara'] = 'Unable to find!';
$data['serviss']['opis_posla'] = 'Unable to find!';
$data['serviss']['utro_mater'] = 'Unable to find!';
$data['serviss']['comment'] = 'Unable to find!';
$data['serviss']['datum'] = 'Unable to find!';
$data['serviss']['datum_otp'] = 'Unable to find!';
$data['serviss']['task_status'] = '0';
$data["total_rows"] = '0';
}
return $data;
}
视图/默认/ servis.php
<div class="clearfix"> </div>
<?php if ($this->session->flashdata('msg')=='1'){ ?>
<div id="msg_container2" class="alert alert-success alert-dismissible" role="alert">
<button id="msg_close_button2" type="button" class="close" onclick="$('#msg_container2').hide();">×</button>
<span id="msg_content2"><?=$this->session->flashdata('msg_data')?></span>
</div>
<?php } ?>
<div class="table-responsive">
<table class="table table-hover table-bordered table_sortable">
<thead>
<tr>
<th class="s_header<?=($sortfield=='id' && $sort=='asc' ? ' s_asc' : ($sortfield=='id' && $sort=='desc' ? ' s_desc' : ''))?>"><a href="<?=url('servis/s/'.$search.'/id/'.($sort!='desc' ? 'desc' : 'asc').'/'.$limit.'/'.$page_num)?>">ID</a></th>
<th class="s_header<?=($sortfield=='ime' && $sort=='asc' ? ' s_asc' : ($sortfield=='ime' && $sort=='desc' ? ' s_desc' : ''))?>"><a href="<?=url('servis/s/'.$search.'/ime/'.($sort!='desc' ? 'desc' : 'asc').'/'.$limit.'/'.$page_num)?>">Ime</a></th>
<th class="s_header<?=($sortfield=='prezime' && $sort=='asc' ? ' s_asc' : ($sortfield=='prezime' && $sort=='desc' ? ' s_desc' : ''))?>"><a href="<?=url('servis/s/'.$search.'/prezime/'.($sort!='desc' ? 'desc' : 'asc').'/'.$limit.'/'.$page_num)?>">Prezime</a></th>
<th class="s_header<?=($sortfield=='br_tel' && $sort=='asc' ? ' s_asc' : ($sortfield=='br_tel' && $sort=='desc' ? ' s_desc' : ''))?>"><a href="<?=url('servis/s/'.$search.'/br_tel/'.($sort!='desc' ? 'desc' : 'asc').'/'.$limit.'/'.$page_num)?>">Broj telefona</a></th>
<th class="s_header<?=($sortfield=='naziv_artikla' && $sort=='asc' ? ' s_asc' : ($sortfield=='naziv_artikla' && $sort=='desc' ? ' s_desc' : ''))?>"><a href="<?=url('servis/s/'.$search.'/naziv_artikla/'.($sort!='desc' ? 'desc' : 'asc').'/'.$limit.'/'.$page_num)?>">Naziv Artikla</a></th>
<th class="s_header<?=($sortfield=='sn_br' && $sort=='asc' ? ' s_asc' : ($sortfield=='sn_br' && $sort=='desc' ? ' s_desc' : ''))?>"><a href="<?=url('servis/s/'.$search.'/sn_br/'.($sort!='desc' ? 'desc' : 'asc').'/'.$limit.'/'.$page_num)?>">Serijski broj</a></th>
<th class="s_header<?=($sortfield=='gar_stanje' && $sort=='asc' ? ' s_asc' : ($sortfield=='gar_stanje' && $sort=='desc' ? ' s_desc' : ''))?>"><a href="<?=url('servis/s/'.$search.'/gar_stanje/'.($sort!='desc' ? 'desc' : 'asc').'/'.$limit.'/'.$page_num)?>">Pod garancijom</a></th>
<th class="s_header<?=($sortfield=='opis_kvara' && $sort=='asc' ? ' s_asc' : ($sortfield=='opis_kvara' && $sort=='desc' ? ' s_desc' : ''))?>"><a href="<?=url('servis/s/'.$search.'/opis_kvara/'.($sort!='desc' ? 'desc' : 'asc').'/'.$limit.'/'.$page_num)?>">Opis Kvara</a></th>
<th class="s_header<?=($sortfield=='opis_posla' && $sort=='asc' ? ' s_asc' : ($sortfield=='opis_posla' && $sort=='desc' ? ' s_desc' : ''))?>"><a href="<?=url('servis/s/'.$search.'/opis_posla/'.($sort!='desc' ? 'desc' : 'asc').'/'.$limit.'/'.$page_num)?>">Opis Posla</a></th>
<th class="s_header<?=($sortfield=='utro_mater' && $sort=='asc' ? ' s_asc' : ($sortfield=='utro_mater' && $sort=='desc' ? ' s_desc' : ''))?>"><a href="<?=url('servis/s/'.$search.'/utro_mater/'.($sort!='desc' ? 'desc' : 'asc').'/'.$limit.'/'.$page_num)?>">Utroseni materijal</a></th>
<th class="s_header<?=($sortfield=='comment' && $sort=='asc' ? ' s_asc' : ($sortfield=='comment' && $sort=='desc' ? ' s_desc' : ''))?>"><a href="<?=url('servis/s/'.$search.'/comment/'.($sort!='desc' ? 'desc' : 'asc').'/'.$limit.'/'.$page_num)?>">Komentar</a></th>
<th class="s_header<?=($sortfield=='datum' && $sort=='asc' ? ' s_asc' : ($sortfield=='datum' && $sort=='desc' ? ' s_desc' : ''))?>"><a href="<?=url('servis/s/'.$search.'/datum/'.($sort!='desc' ? 'desc' : 'asc').'/'.$limit.'/'.$page_num)?>">Datum zaprimanja</a></th>
<th class="s_header<?=($sortfield=='datum_otp' && $sort=='asc' ? ' s_asc' : ($sortfield=='datum_otp' && $sort=='desc' ? ' s_desc' : ''))?>"><a href="<?=url('servis/s/'.$search.'/datum_otp/'.($sort!='desc' ? 'desc' : 'asc').'/'.$limit.'/'.$page_num)?>">Datum otprimanja</a></th>
<th class="s_header<?=($sortfield=='task_status' && $sort=='asc' ? ' s_asc' : ($sortfield=='task_status' && $sort=='desc' ? ' s_desc' : ''))?>"><a href="<?=url('servis/s/'.$search.'/task_status/'.($sort!='desc' ? 'desc' : 'asc').'/'.$limit.'/'.$page_num)?>">Posao zavrsen</a></th>
</tr>
</thead>
<tbody>
<?php
if (!empty($task_data['serviss'])){
foreach ($task_data['serviss'] as $t_key => $t_value) { ?>
<tr>
<td><a href="<?=url('servis/info/'.$t_value['id'])?>"><?=$t_value['naziv_artikla']?></a></td>
<td><?=$t_value['ime']?></td>
<td><?=$t_value['prezime']?></td>
<td><?=$t_value['br_tel']?></td>
<td><?=$t_value['naziv_artikla']?></td>
<td><?=$t_value['sn_br']?></td>
<td><?=$t_value['gar_stanje']?></td>
<td><?=$t_value['opis_kvara']?></td>
<td><?=$t_value['opis_posla']?></td>
<td><?=$t_value['utro_mater']?></td>
<td><?=$t_value['comment']?></td>
<td><?=$t_value['datum']?></td>
<td><?=$t_value['datum_otp']?></td>
<td><?=$this->selects->task_status('','',$t_value['task_status'],1)?></td>
</tr>
<?php }}else{ ?>
<tr>
<td>No Information</td>
<td>No Information</td>
<td>No Information</td>
<td>No Information</td>
<td>No Information</td>
<td>No Information</td>
<td>No Information</td>
<td>No Information</td>
<td>No Information</td>
<td>No Information</td>
<td>No Information</td>
<td>No Information</td>
<td>No Information</td>
<td>No Information</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?=$pagination_links?>
控制器/ Servis.php
public function s(){
if ($this->session->userdata('user_id')==''){
header('Location: '.url('home'));
}else{
$data = array();
$data['search'] = urldecode(($this->uri->segment(4)!='' ? $this->uri->segment(4) : 'search'));
$data['sortfield'] = ($this->uri->segment(5)!='' ? $this->uri->segment(5) : 'default');
$data['sort'] = ($this->uri->segment(6)!='' ? $this->uri->segment(6) : 'sort');
$data['limit'] = ($this->uri->segment(7)!='' ? $this->uri->segment(7) : 20);
$data['page_num'] = ($this->uri->segment(8)!='' ? $this->uri->segment(8) : 1);
$data['task_data'] = $this->master->get_tasks($data['limit'],'',$data['page_num'],$data['search'],$data['sortfield'],$data['sort']);
$this->load->library('pagination');
$config['uri_segment'] = 8;
$config['num_links'] = 2;
$config['base_url'] = url('servis/s/'.$data['search'].'/'.$data['sortfield'].'/'.$data['sort'].'/'.$data['limit']);
$config['total_rows'] = $data['task_data']['total_rows'];
$config['per_page'] = $data['limit'];
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
$data['pagination_links'] = $this->pagination->create_links();
$data['meta']['title'] = 'Servis';
$theme = $this->master->get_theme();
$this->load->view($theme.'/servis',$data);
}
}
如果有人知道如何解决此问题以及导致此问题的原因,请与我联系或写下答案。
我非常感谢那些试图克服错误的人。
现在我发出消息“无法找到”,显然现在是从数据库中检索数据的问题。 My view after i changed the code
此外,@ Alex Andrei来自var_dump ....
array(14) { ["id"]=> string(15) "Unable to find!" ["ime"]=> string(15) "Unable to find!" ["prezime"]=> string(15) "Unable to find!" ["br_tel"]=> string(15) "Unable to find!" ["naziv_artikla"]=> string(15) "Unable to find!" ["sn_br"]=> string(15) "Unable to find!" ["gar_stanje"]=> string(15) "Unable to find!" ["opis_kvara"]=> string(15) "Unable to find!" ["opis_posla"]=> string(15) "Unable to find!" ["utro_mater"]=> string(15) "Unable to find!" ["comment"]=> string(15) "Unable to find!" ["datum"]=> string(15) "Unable to find!" ["datum_otp"]=> string(15) "Unable to find!" ["task_status"]=> string(1) "0" }
答案 0 :(得分:0)
我认为
foreach ($task_data['serviss'] as $t_key => $t_value) {}
should be
foreach($task_data as $t_key => $t_value) {}