0
Here are the codes:
VIEW:
<div class="container">
<?php
echo form_open_multipart('admin/exibe_fotos/index');
?>
<div class="form-group">
<label for="categoria">Selecione a categoria desejada:</label>
<select name="categorias" class="form-control">
<?php foreach ($listarCategorias->result() as $row) : ?>
<option value="<?php echo $row->idCategoria; ?>"><?php echo $row->dscCategoria; ?></option>
<?php endforeach ?>
</select>
</div>
<input type="submit" class="btn btn-primary btn-lg float-right" value="Buscar fotos">
<?php
echo form_close();
?>
</div>
<div class="container-galeria">
<?php foreach ($mostrarFotos->result() as $row) : ?>
<div class="card row mx-3 my-3" style="width: 18rem; display:inline-block">
<img class="card-img-top" src="<?php echo base_url('assets/upload/'.$row->caminhoImagem); ?>" alt="<?php echo $row->tituloImagem; ?>">
<div class="card-body">
<h5 class="card-title"><?php echo $row->tituloImagem; ?></h5>
<a href="#" class="btn btn-primary">Marcar</a>
</div>
</div>
<?php endforeach ?>
</div>
CONTROLLER:
public function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
public function index()
{
$this->load->view('layout/admin/sidebar');
$this->load->model('admin/tbdimagem');
$dados["mostrarFotos"] = $this->tbdimagem->listarImagensCategoria();
$this->load->view('admin/marcacao_fotos', $dados);
$this->load->view('layout/admin/footer');
}
MODEL:
function listarImagensCategoria()
{
$idCategoria = $this->input->post('categorias');
$subselect = "SELECT idImagem FROM imagem_categoria WHERE idCategoria = '$idCategoria'";
$this->db->select('*');
$this->db->from('tbdimagem');
$this->db->where("idImagem", "$subselect");
$query = $this->db->get();
return $query;
}
When I select a category and click on the button to bring the photos, I simply get redirected to that screen:
First you should not use post variables in the model, model is part of bank
– Otto
Could you give an example using my same code, how it would look without passing the post variable in the model? It would help a lot... Everywhere I look is this way...
– igorarmelin
The best would be to pass the variable in the method (of the model) by the controller
– Otto
For example, in the controller it would look like this: $idCategoria = $this->input->post('categories'); and in the call to the model, I would go like this: $this->load->model('admin/tbdimagem', $idCategoria); So in my model function, I would put it like this: Function listrImagenCategory($idCategory){}
– igorarmelin
Here not $this->load->model('admin/tbdiming', $idCategory); here yes $this->tbdiming->listingImagensCategory();, the model load is just the load
– Otto