Welcome Guest, Not a member yet? Register   Sign In
_assign_libraries error when adding to the database
#1

[eluser]Tomer Simis[/eluser]
Hello guys, im new to the frameworks world and i choose the codeigniter to start. I saw the videos on the site and a few tutorials on the internet. Now im practicing, and im getting a error when im doing a insert to the database.

The error: Fatal error: Call to undefined method Pedidos::_assign_libraries() in C:\wamp\www\codeigniter\system\libraries\Loader.php on line 185

Controller
Code:
class Pedidos extends Controller{
    
    function Pedidos(){
        parent::Controller();
    }
    
    function index(){
        $this->load->view('pedidos');
    }
    
    function enviar(){
        $this->load->model('pedidos');
        $nome = $this->input->post('nome');
        $email = $this->input->post('email');
        $pedido = $this->input->post('pedido');
        $this->Pedidos_model->enviarPedido($nome,$email,$pedido);
    }
    
}

Model
Code:
class Pedidos_model extends Model{
    
    function Pedidos_model(){
        parent::Model();
    }
    
    function enviarPedido($nome,$email,$pedido){
        $this->db->query("INSERT INTO pedidos (nome,email,pedido) VALUES ('$nome','$email','$pedido')");
    }
    
}

View
Code:
<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <meta name="author" content="Tomer Simis" />

    <title>Pedidos</title>
</head>

<body>

<form action="enviar" name="enviar" method="post" enctype="text/plain">

<p>
<label>Nome
&lt;input type="text" name="nome" maxlength="20" /&gt;
</label><br />
</p>

<p>
<label>Email
&lt;input type="text" name="email" maxlength="50" /&gt;
</label><br />
</p>

<p>Pedido
&lt;textarea name="pedido"&gt;&lt;/textarea>
</p>

&lt;input type="submit" value="Enviar pedido" /&gt;

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;

Please, help me guys :down:
Sorry for any english mistake, im brazillian

Thanks
#2

[eluser]imn.codeartist[/eluser]
Instead of This code
Code:
function enviar(){
        $this->load->model('pedidos');
        $nome = $this->input->post('nome');
        $email = $this->input->post('email');
        $pedido = $this->input->post('pedido');
        $this->Pedidos_model->enviarPedido($nome,$email,$pedido);
    }

Try this and see if this work first
Code:
function enviar(){
        $this->load->model('pedidos');
        $nome = $_POST['nome'];
        $email = $_POST['email'];
        $pedido = $_POST['pedido'];
        $this->Pedidos_model->enviarPedido($nome,$email,$pedido);
    }

Your code has a lot needs to modify but try using some core php stuffs first
#3

[eluser]Tomer Simis[/eluser]
i got the same error
Fatal error: Call to undefined method Pedidos::_assign_libraries() in C:\wamp\www\codeigniter\system\libraries\Loader.php on line 185

Please, help me =/
#4

[eluser]Colin Williams[/eluser]
It seems that you have accidentally altered the core model class, which is where that method exists.
#5

[eluser]Tomer Simis[/eluser]
I've downloaded code igniter again and replaced the files, and i still got the error. I have uploaded my codeigniter folder with my controllers,views and models: http://www.radioelevasom.com.br/codeigniter.rar
Help me please
#6

[eluser]Tomer Simis[/eluser]
I've found a solution for the bug on the codeigniter bug tracker. I deleted the line 185 on the Loader class and the error stopped. Now im getting another error:
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Pedidos::$PedidosModel

Filename: controllers/pedidos.php

Line Number: 20

Fatal error: Call to a member function enviarPedido() on a non-object in C:\wamp\www\codeigniter\system\application\controllers\pedidos.php on line 20

And before this error, i was getting another error: undefined index when i was posting, so i moved the POST vars to the model and the error stopped.

PS: I have changed the "Pedidos" model name for "PedidosModel", and the filename for "pedidosmodel.php"

Please guys, help me
#7

[eluser]jedd[/eluser]
Yes - removing the _assign_libraries() call from the core Loader class is likely to break other things.

The problem here is that you're experiencing a unique problem. This is why we tend to think it's something you've changed or done, rather than something wrong with the CI files.

Hmm, I was about to suggest you go through the same process again, only this time checking each time you add a new file, or at least confirming the basic system is working, but re-scanning your original question again I see that this bit might be a problem:

Code:
// controller ...
    function enviar(){
        $this->load->model('pedidos');

Code:
// model ...
class Pedidos_model extends Model{

In your controller, you really need to load the name of your model - in this case Pedidos_model and not the name of your controller (pedidos).

Try changing your controller to:
Code:
$this->load->model('Pedidos_model');
#8

[eluser]skunkbad[/eluser]
I just had the same error, and it turned out that I was calling a model, and the model file did exist, but had the wrong model name:

file: orders.php

class Not_orders extends Model {
//...
}
#9

[eluser]skaterdav85[/eluser]
I was getting something similar. My error was:
codeigniter Fatal error: Call to undefined method About_model::_assign_libraries() on line 185

but then i realized that my About_model class did not extend the Model class. So if you haven't checked already, check to make sure your model is extending the Model class.




Theme © iAndrew 2016 - Forum software by © MyBB