2
I have a form where two multiple selects is loaded, here the code:
<div class="form-group">
<label for="categorias[]">Selecione a(s) categoria(s) referente(s) a foto:</label>
<select name="categorias[]" class="form-control" multiple="multiple">
<?php foreach ($categorias as $categoria) : ?>
<option value="<?= $categoria['idCategoria'] ?>"><?= $categoria['dscCategoria'] ?></option>
<?php endforeach ?>
</select>
</div>
<div class="form-group">
<label for="subcategorias[]">Selecione a(s) subcategoria(s) referente(s) a foto:</label>
<select name="subcategorias[]" class="form-control" multiple="multiple">
<?php foreach ($subcategorias as $subcategoria) : ?>
<option value="<?= $subcategoria['idSubcategoria'] ?>"><?= $subcategoria['dscSubcategoria'] ?></option>
<?php endforeach ?>
</select>
</div>
The controller code that handles this view is as follows:
$this->load->model('admin/tbdcategoria');
$lista['categorias'] = $this->tbdcategoria->listarCategorias();
$dados['categorias'] = array('categorias' => $lista['categorias']);
$this->load->model('admin/tbdsubcategoria');
$lista['subcategorias'] = $this->tbdsubcategoria->listarSubcategorias();
$dados['subcategorias'] = array('subcategorias' => $lista['subcategorias']);
$this->load->view('layout/admin/sidebar');
$this->load->view('admin/upload_fotos', $dados);
$this->load->view('layout/admin/footer');
The model code for data display is as follows:
function listarCategorias()
{
return $this->db->get('tbdcategoria')->result_array();
}
function listarSubcategorias()
{
return $this->db->get('tbdsubcategoria')->result_array();
}
The problem is this, in the view instead of loading the categories / subcategories registered in the database, is returning "Undefined Index"
It makes it easier for us, what exact line is generating this error ?
– Otto
<option value="<?= $category['idCategoria'] ? >"><?= $category['dscCategoria'] ? ></option> <option value="<?= $subcategory['idSubcategory'] ? >"><?= $subcategory['dscSubcategory'] ? ></option> In these 2 index returns undefined
– igorarmelin
Have you checked if you are mounting this data ? tried to do a var_dump and Talz to be sure ?
– Otto
This error is quite explanatory, you are trying to use an array key that does not exist
– Otto
before using an array key, make a check if this key exists.
– Kayo Bruno
var_dump is returning "NULL"
– igorarmelin
But there is, because if I leave only one select searching for data from one model only, it loads, from the moment I call another select with another model, it passes to not loading either one
– igorarmelin
As I noticed, if I pass to the example $list['categories'] does not work, if I pass only $list, it works. But then I’ll never be able to upload data to my other select
– igorarmelin