CodeIgniter Forums

Full Version: Call to undefined method my_model:dame_articulos()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]lucasvm[/eluser]
Hello

Im getting this error when i try to acces to the article page on my website, im doing this:

Code:
function muestra($id){
       $this->load->model('Articulos_model');

       //pido al modelo el artículo que se desea ver
       $arrayArticulos = $this->Articulos_model->dame_articulos($id);
       $numero_posts = $this->Articulos_model->dame_nro_posts();
       $datos_articulos = array('articulos' => $arrayArticulos,
                                'numero_de_posts' => $numero_posts);
       if (!$arrayArticulos){
                    show_404();
                }else
                    {
        $this->load->helper('url');
        $this->load->view('header');
        $this->load->view('articulos', $datos_articulos);
        $this->load->view('footer');
        }
   }

So the model articulos_model dooes exists, also the function dame_articulo existis and im doing this in articulos_model:

Code:
function dame_articulos($id){
            $sql = "myquery
                WHERE id =  '$id'";
        $query = $this->db->query($sql);
        $fav = $query->result_array();

        foreach($query->result() AS $row):
            $rows = $row;
            return $rows;
        endforeach;
        }

Does anybody knows why im getting this error? and how can i fix it?

El Forum

[eluser]InsiteFX[/eluser]
Try this, also make sure that you saved your model with all lowercase name!
You should also read the CodeIgniter User Guide - General Style and Syntax.
Code:
function muestra($id){
       $this->load->model('articulos_model');

       //pido al modelo el artículo que se desea ver
       $arrayArticulos = $this->articulos_model->dame_articulos($id);
       $numero_posts = $this->articulos_model->dame_nro_posts();
       $datos_articulos = array('articulos' => $arrayArticulos,
                                'numero_de_posts' => $numero_posts);
       if (!$arrayArticulos){
                    show_404();
                }else
                    {
        $this->load->helper('url');
        $this->load->view('header');
        $this->load->view('articulos', $datos_articulos);
        $this->load->view('footer');
        }
   }

InsiteFX

El Forum

[eluser]lucasvm[/eluser]
im getting the same error...

i dont know why, the name is the same as the function...

El Forum

[eluser]TWP Marketing[/eluser]
@insitefx The model name needs to be Capitalized in almost all usage. It's the file name that is lowercase.

@lucasvm. Your controller function looks ok. As Insitefx said, check the filename itself, it should be lower case.

Code:
...
function muestra($id){
       $this->load->model('Articulos_model'); // <-- this is correct

       //pido al modelo el artículo que se desea ver
       $arrayArticulos = $this->Articulos_model->dame_articulos($id); // <-- this is correct
       $numero_posts = $this->Articulos_model->dame_nro_posts(); // <-- this is correct
       $datos_articulos = array('articulos' => $arrayArticulos,
                                'numero_de_posts' => $numero_posts);
       if (!$arrayArticulos){
                    show_404();
                }else
                    {
        $this->load->helper('url');
        $this->load->view('header');
        $this->load->view('articulos', $datos_articulos);
        $this->load->view('footer');
        }
   }
...

El Forum

[eluser]lucasvm[/eluser]
Thank you, the file name calls articulos_model.php located in models folder.

I dont know what to do Sad

El Forum

[eluser]InsiteFX[/eluser]
@TWP
Wrong! If you read the code in the loader of the model you will see that it uppercases the model name.
Code:
$model = strtolower($model);

require_once($mod_path.'models/'.$path.$model.'.php');
$model = ucfirst($model);

InsiteFX

El Forum

[eluser]TWP Marketing[/eluser]
@InsiteFX, I stand corrected. It seems the User Guide is also incorrect, or at least irrelevant, since the loader will force the capitalization of model names if the coder does not. I have learned something, thanks.