Welcome Guest, Not a member yet? Register   Sign In
Error while running CodeIgniter
#1

[eluser]elmne[/eluser]
I have the following problem

I created a model class like this

Code:
function Customertype()
    {
        // Call the Model constructor
        parent::Model();
    }
    


    function add_customertype()
    {
        $this->customer_type = $_POST['customer_type'];

        $this->db->insert('entries', $this);
    }


}


I then created a controller class like this

Code:
<?php
class Customertype extends Controller {

    function index()
    {
        echo 'Hello World!';
    }
    
    
    function customertype_add()
    {
        $this->load->view('admin/customertype_add');
    }
    
    function customertype_add_process()
    {
       $this->load->model('Customertype','',TRUE);  // TRUE autoconnects model to database
        $this->Customertype->add_customertype();
       $this->load->view('admin/customertype_added');
    }
    
    
    
}
?>


I then created a view class like this



Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form id="form1" name="form1" method="post" action="customertype_add_process"&gt;
  <p>&nbsp;</p>
  <p>Customer Type:
    &lt;input type="text" name="customer_type" /&gt;
  </p>
  <p>
    &lt;input type="submit" name="submit" value="submit" /&gt;
  </p>
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;


But when the view is displayed and i click "submit", i get the following error

Quote:class Customertype extends Model { var $customer_type_id = ''; var $customer_type = ''; function Customertype() { // Call the Model constructor parent::Model(); } function add_customertype() { $this->customer_type = $_POST['customer_type']; $this->db->insert('entries', $this); } }
Fatal error: Call to undefined method Customertype::_assign_libraries() in C:\xxxxx\xxxxx\www\xxxx\system\libraries\Loader.php on line 185


Can someone please advice on the cause for the failure?
#2

[eluser]WanWizard[/eluser]
You can't have a model and a controller (two classes) with the same name.
#3

[eluser]elmne[/eluser]
That solved the problem. Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB