2
Good night!
I need to return the value of a table in codeigniter but it is acknowledging the error below:
PHP Error was encountered
Severity: Notice
Message: Undefined variable: name
Filename: paineladmin/categories.php
Line Number: 7
But my role in the model is correct, below:
public function get_bynome($nome=NULL){
if($nome != NULL):
$this->db->where('nome', $nome);
$this->db->limit(1);
return $this->db->get('categorias');
else:
return FALSE;
endif;
}
And the call on the view is like this:
echo '<div class="small-12 columns">';
echo breadcrumb();
$query = $this->categorias->get_bynome($nome)->row();
erros_validacao();
get_msg('msgok');
echo form_open('categorias/cadastrar', array('class'=>'custom'));
echo form_fieldset('Cadastrar nova categoria');
echo form_label('Nome');
echo '<div class="row">';
echo '<div class="small-5 columns">';
echo form_input(array('name'=>'nome'), set_value('nome'), 'autofocus');
echo '</div>';
echo '</div>';
echo form_label('Categoria Pai');
echo '<div class="row">';
echo '<div class="small-5 columns">';
echo form_dropdown('Categoria Pai', $query->nome, 'Selecione uma opção');
echo '</div>';
echo '</div>';
public function cadastrar(){
//esta_logado();
$data['query'] = $this->categorias->get_bynome($nome)->row();
$this->load->view("categorias", $data);
It seems that the variable is not declared something like this, I did not find the error.
Which of the 2 is the paineladmin/categories.php file?
– Papa Charlie
The view, the bottom
– Eduardo Paludo
I don’t know how the CI renders the view...
$query = $this->categorias->get_bynome($nome)->row()
the view is receiving the right $name variable? From avar_dump( $nome )
at the beginning of the view.– Papa Charlie
Yes, the view is receiving the $name variable of the get_byname function of the model. No use with var_dump($name) hehe
– Eduardo Paludo
Could put the code that calls the view?
– rray
public Function register(){ //esta_logated(); $data['query'] = $this->categories->get_byname($name)->Row(); $this->load->view("categories", $data);
– Eduardo Paludo
If
$nome
comes from a POST/GET, you should recover like this:$nome = $this->input->post('nome');
that in thecadastrar()
.– rray