Welcome Guest, Not a member yet? Register   Sign In
Undefined method.
#1

[eluser]Havok[/eluser]
Fatal error: Call to undefined method Register::create() in C:\wamp\www\application\controllers\register.php on line 12

The Model
Code:
class Register_model extends CI_Model
{
    
    function __construct()
    {
        parent::__construct();
    }
    
    function create()
    {
        if ($this->input->post('create') == TRUE)
        {
            switch($this->input->post('month'))
            {
                case "January":
                    $month = 01;
                    break;
                case "February":
                    $month = 02;
                    break;
                case "March":
                    $month = 03;
                    break;
                case "April":
                    $month = 04;
                    break;
                case "May":
                    $month = 05;
                    break;
                case "June":
                    $month = 06;
                    break;
                case "July":
                    $month = 07;
                    break;
                case "August":
                    $month = 08;
                    break;
                case "September":
                    $month = 09;
                    break;
                case "October":
                    $month = 10;
                    break;
                case "November":
                    $month = 11;
                    break;
                case "December":
                    $month = 12;
                    break;
            }
            $reg_error = false;
            $errors = array();
            $referer = $this->input->post('referer');
            $dob = $month . "/" . $this->input->post('day') . "/" . $this->input->post('year');
            $join_date = date("F d, Y");
            $todays_month = date("F");
            $todays_date = date("d");        
            $todays_year = date("Y");    
            $bday = mktime(0,0,0,$month, $this->input->post('day'), $this->input->post('year'));  //birthday
            $min_bday = mktime(0,0,0,$todays_month, $todays_date, ($todays_year - 13));
            $user_exists = mysql_num_rows(mysql_query("SELECT * FROM `users` WHERE `username` = '$this->input->post(username)'"));
        
            if($user_exists >= '1')
            {
                $reg_error = TRUE;
                array_push($errors, "Username has been taken.");
            }
            if($this->input->post('pass') !== $this->input->post('confirm'))
            {
                $reg_error = TRUE;
                array_push($errors, "Passwords did not match.");
            }
            if($bday < $min_bday)
            {
                $reg_error = TRUE;
                array_push($errors, "You're not old enough to play.");
            }
            if($this->input->post('agree') == FALSE)
            {
                $reg_error = TRUE;
                array_push($errors, "You did not agree to our Terms of Service.");
            }
            
            if($reg_error == FALSE)
            {
                $data = array(
                    'username' => '$this->input->post(data)',
                    'password' => '$pw',
                    'join_date' => '$join_date',
                    'ip_address' => '$_SERVER[REMOTE_ADDR]',
                    'dob' => '$dob',
                    'currency' => '0;50;50;',
                    'referer' => '$referer');
                    
                $this->db->insert('users', $data);
                
                echo '<h1>Registration Successful!</h1>';
                    
            }else{
                
                foreach($errors as $item)
                {
                    echo $item . "<br/><br/>";
                }
            }
        }
    }
}

The controller
Code:
class Register extends CI_Controller
{
    
    function index()
    {
        $this->load->model('Register');
                
        if($this->input->post('create') != FALSE)
        {
            $this->Register->create();
            echo '1';
        }
        
        $this->load->view('register');
    }
    
}

Clearly the function is there... why is this happening still?
#2

[eluser]Mirge[/eluser]
Code:
class Register_model extends CI_Model
Code:
$this->load->model('Register');

See the problem? Smile
#3

[eluser]Havok[/eluser]
Apparently not. Changing Register to Register_model produces an error.

Unable to locate the model you have specified: register_model
#4

[eluser]Mirge[/eluser]
You named the file register.php - change your class name to Register (or change your filename to register_model.php).

They're not consistent. For example, it SHOULD appear like this:

filename: register.php
class: class Register extends CI_Model { ... }
load: $this->load->model('register');
call: $this->register->create();
#5

[eluser]Havok[/eluser]
Thank you much!
#6

[eluser]Mirge[/eluser]
no worries




Theme © iAndrew 2016 - Forum software by © MyBB