Welcome Guest, Not a member yet? Register   Sign In
"insert" - SQL-Problem using the Active Record Class
#11

[eluser]NachoF[/eluser]
I see... so what do you recommend I do?
#12

[eluser]Derek Jones[/eluser]
[quote author="NachoF" date="1242103997"]I see... so what do you recommend I do?[/quote]

Well, there's no reason to send the entire class object to an insert/update query, and in fact would cause problems on all but the simplest of model classes. That example in the docs was likely written in haste, and should be modified so that others don't use it as a pattern. Rather, simply use a separate object or array that contains only the items you want, e.g.

Code:
$data = array('foo' => 'bar');
$this->db->insert('tablename', $data);
#13

[eluser]NachoF[/eluser]
Yes, thats what I ended up doing.. thanks.
#14

[eluser]pankaj[/eluser]
[quote author="NachoF" date="1242119426"]Yes, thats what I ended up doing.. thanks.[/quote]

@Derek Jones thanks for explanation about $this object but I want you to see this

Code:
function insert_entry()
    {
        $this->title   = $_POST['title']; // please read the below note
        $this->content = $_POST['content'];
        $this->date    = time();

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

in user guide at http://ellislab.com/codeigniter/user-gui....html#what

this example is using $this object for inserting data. and I am sure this will not work. and this example should be removed from the user guide


---
#15

[eluser]TheFuzzy0ne[/eluser]
That example should work fine, so long as it's called from within the model, and you have set the appropriate properties first.

Controller:
Code:
$this->user_model->username = "TheFuzzy0ne";
$this->user_model->email = "[email protected]";
$this->user_model->password = "P455W0RD";
$this->user_model->insert_user();

Model:
Code:
function insert_user()
{
    $this->db->insert('users', $this);
}

Called from within the model, $this represents the model, not the CodeIgniter Super Object.
#16

[eluser]pankaj[/eluser]
[quote author="TheFuzzy0ne" date="1242487511"]That example should work fine, so long as it's called from within the model, and you have set the appropriate properties first.

Controller:
Code:
$this->user_model->username = "TheFuzzy0ne";
$this->user_model->email = "[email protected]";
$this->user_model->password = "P455W0RD";
$this->user_model->insert_user();

Model:
Code:
function insert_user()
{
    $this->db->insert('users', $this);
}

Called from within the model, $this represents the model, not the CodeIgniter Super Object.[/quote]

this method is not working that is the main problem I am facing I have posted new thread for that.
at http://ellislab.com/forums/viewthread/114514/P0/




Theme © iAndrew 2016 - Forum software by © MyBB