• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Undefined method that's actually defined.

#1
[eluser]behdesign[/eluser]
Here's the model I'm calling, that I autoload when CI starts:

Code:
<?

/**
* @filesource app/models/proctor.php
* @notes Handles test administration, monitoring and issuing of certificates.
*/

class Proctor extends Model{
    
    function __construct(){
        
        parent::Model();
        
    }
}

function get_verification_methods($media_id){
    
    $ret = array();
    
    $sql = sprintf('SELECT * FROM `media-verification` AS mv INNER JOIN verification AS v ON mv.method=v.id WHERE media_id=%s', $media_id);
    $query = $this->db->query($sql);
    $_array = $query->result_array();
    
    foreach($_array as $key => $value){
        
        $ret[$value['media']] = $value['name'];
    }
    
    return $ret;

}

?>

When I call it from the controller, I get the error:

Code:
Call to undefined method Proctor::get_verification_methods()

Can anyone tell me why this would be?

#2
[eluser]bhogg[/eluser]
Looks like the brackets are in the wrong place... you're ending the Proctor class before declaring the function.

#3
[eluser]Ivan A. Zenteno[/eluser]
You are closing the model before the method of the controller

Check like this:
Code:
<?
/**
* @filesource app/models/proctor.php
* @notes Handles test administration, monitoring and issuing of certificates.
*/

class Proctor extends Model{
    
    function __construct()
    {    
        parent::Model();  
    }

    function get_verification_methods($media_id)
    {
        $ret = array();
        $sql = sprintf('SELECT * FROM `media-verification` AS mv INNER JOIN verification AS v ON mv.method=v.id WHERE media_id=%s', $media_id);
        $query = $this->db->query($sql);
        $_array = $query->result_array();
    
        foreach($_array as $key => $value)
        {    
            $ret[$value['media']] = $value['name'];
        }    
        return $ret;
    }
}
?>

#4
[eluser]behdesign[/eluser]
Lord, I hate closures. Thank you all.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.