CodeIgniter列表不尊重权限并显示太多信息

时间:2015-04-15 01:27:43

标签: php codeigniter

如何使此代码仅列出相应供应商的销售额?目前它正在显示所有订单。

未正确列出来自数据库的数据,未正确过滤。

控制器:

function index(){
$this->gerenciar();}

function gerenciar(){

    $this->load->library('pagination');

    $config['base_url'] = base_url().'index.php/os/gerenciar/';
    $config['total_rows'] = $this->os_model->count('os');
    $config['per_page'] = 10;
    $config['next_link'] = 'Próxima';
    $config['prev_link'] = 'Anterior';
    $config['full_tag_open'] = '<div class="pagination alternate"><ul>';
    $config['full_tag_close'] = '</ul></div>';
    $config['num_tag_open'] = '<li>';
    $config['num_tag_close'] = '</li>';
    $config['cur_tag_open'] = '<li><a style="color: #2D335B"><b>';
    $config['cur_tag_close'] = '</b></a></li>';
    $config['prev_tag_open'] = '<li>';
    $config['prev_tag_close'] = '</li>';
    $config['next_tag_open'] = '<li>';
    $config['next_tag_close'] = '</li>';
    $config['first_link'] = 'Primeira';
    $config['last_link'] = 'Última';
    $config['first_tag_open'] = '<li>';
    $config['first_tag_close'] = '</li>';
    $config['last_tag_open'] = '<li>';
    $config['last_tag_close'] = '</li>';

    $this->pagination->initialize($config);     

    $this->data['results'] = $this->os_model->get('os','idOs,dataInicial,garantia,descricaoProduto,defeito,usuarios_id,status,observacoes,desconto,trocas','',$config['per_page'],$this->uri->segment(3));

    $this->data['view'] = 'os/os';
    $this->load->view('tema/topo',$this->data);
}

MODEL:

    function get($table,$fields,$where='',$perpage=0,$start=0,$one=false,$array='array'){

    $this->db->select($fields.',clientes.nomeCliente, clientes.tabelaPreco');
    $this->db->from($table);
    $this->db->join('clientes','clientes.idClientes = os.clientes_id');
    $this->db->limit($perpage,$start);
    $this->db->order_by('idOs','desc');
    if($where){
        $this->db->where($where);
    }

    $query = $this->db->get();

    $result =  !$one  ? $query->result() : $query->row();
    return $result;
}

查看:

<?php           
    foreach ($results as $r) {
        if ($this->session->userdata('id') == $r->usuarios_id || $this->session->userdata('id') == '1') {
        $dataInicial = date(('d/m/Y'),strtotime($r->dataInicial));
        echo '<tr>';
        echo '<td>'.$r->idOs.' -'.$r->usuarios_id.'</td>';
        echo '<td>'.$r->nomeCliente.'</td>';
        echo '<td>'.$dataInicial.'</td>';
        echo '<td>'.$r->status.'</td>';

        echo '<td>';
        if($this->permission->checkPermission($this->session->userdata('permissao'),'vOs')){
            echo '<a style="margin-right: 1%" href="'.base_url().'index.php/os/visualizar/'.$r->idOs.'" class="btn tip-top" title="Ver mais detalhes"><i class="icon-eye-open"></i></a>'; 
        }
        if($this->permission->checkPermission($this->session->userdata('permissao'),'eOs')){
            echo '<a style="margin-right: 1%" href="'.base_url().'index.php/os/editar/'.$r->idOs.'" class="btn btn-info tip-top" title="Editar OS"><i class="icon-pencil icon-white"></i></a>'; 
        }
        if($this->permission->checkPermission($this->session->userdata('permissao'),'dOs')){
        echo '<a href="#modal-excluir" role="button" data-toggle="modal" os="'.$r->idOs.'" class="btn btn-danger tip-top" title="Excluir OS"><i class="icon-remove icon-white"></i></a>  '; 
        }
        echo  '</td>';
        echo '</tr>';
    }
}?>

1 个答案:

答案 0 :(得分:0)

您没有过滤模型中的记录。 <{1}}为空,因此sql将返回所有记录。

您应该从会话或参数中获取供应商ID,然后将其传递给具有where条件的模型。