Codeigniter - Query in DB

2

Good evening!

I need to return the value of a table in codeigniter but it is acknowledging the error below:

  

A PHP Error was encountered

     

Severity: Notice

     

Message: Undefined variable: name

     

Filename: paneladmin / categories.php

     

Line Number: 7

But my function in the model is correct, it follows 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 in the view looks 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.

    
asked by anonymous 05.08.2014 / 05:50

2 answers

2

As you can see, this error is because it is not passing the variable to the view, this must be done from your controller, and I do not know if I am right, but this part is from your correct controller:

public function cadastrar(){
  //esta_logado();
  $data['query'] = $this->categorias->get_bynome($nome)->row();    
  $this->load->view("categorias", $data);

If yes, you should have done so

public function cadastrar(){
  //esta_logado();
  $data['query'] = $this->categorias->get_bynome($nome)->row();    
  $data['nome'] = $nome; //passar a variavel nome para a view
  $this->load->view("categorias", $data);

By the time you asked the question, you should have solved it, but only confirm that it was.

    
05.09.2014 / 16:00
0

NOTICE errors in PHP can be ignored by calling the following function at the beginning of the file:

error_reporting(E_ALL ^ E_NOTICE);

In Codeigniter, this function is called in the index.php file. You can check between lines 31 and 47 in the framework source code:

link

    
05.08.2014 / 19:35