CodeIgniter Forums
Undefined method stdClass::save()? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Undefined method stdClass::save()? (/showthread.php?tid=27303)



Undefined method stdClass::save()? - El Forum - 02-06-2010

[eluser]rockstyle[/eluser]
Something like this in method when i submit:
Code:
$bank->title = $this->input->post('title');
        $bank->url = $this->input->post('url');
        $bank->description = $this->input->post('description');
        $bank->forum_url = $this->input->post('forum_url');
        $bank->updated_at = unix_to_human(time(), TRUE, 'eu');
        $bank->save();

And Error I got:
Code:
Fatal error: Call to undefined method stdClass::save() in...

Help Tongue


Undefined method stdClass::save()? - El Forum - 02-06-2010

[eluser]theprodigy[/eluser]
need a little more information please. Is your $bank class a custom library, model, etc
What methods do you have written for it?
If it's a model, are you extending an ORM of some kind, extending Model, etc


Undefined method stdClass::save()? - El Forum - 02-07-2010

[eluser]rockstyle[/eluser]
I'm mainly using Doctrine. $bank is an object with variables from database table. I think just save(); doesn't work but can't figure out why...

Code:
public function submit() {
        
        $bank->title = $this->input->post('title');
        $bank->url = $this->input->post('url');
        $bank->description = $this->input->post('description');
        $bank->forum_url = $this->input->post('forum_url');
        $bank->updated_at = unix_to_human(time(), TRUE, 'eu');
        $bank->save();
        
        $this->load->view('submit_success');
    
    }

Just that is executed when i click submit button, but view doesn't load and there is error Wink


Undefined method stdClass::save()? - El Forum - 02-07-2010

[eluser]theprodigy[/eluser]
try commenting out the save method, and print_r-ing the $bank object.

this may be a simple question (and due to debugging purpose, please don't get offended by any implications), but are you loading the bank model? Is your bank model extending Doctrine_Record and not Model?


Undefined method stdClass::save()? - El Forum - 02-07-2010

[eluser]rockstyle[/eluser]
Code:
stdClass Object ( [title] => Otwartapestka.pl [url] => http://otwartapestka.pl [description] => Zasiejemy cala Polske [forum_url] => http://otwartapeskta.info/viewtopic.php?v=23123 [updated_at] => 2010-02-07 12:10:24 )

And Model which obviously extends Doctrine_record
Code:
<?php
class Bank extends Doctrine_Record {

    public function setTableDefinition() {
        $this->hasColumn('title', 'string', 255);
        $this->hasColumn('description', 'string', 255);
        $this->hasColumn('category_id', 'integer', 4);
        $this->hasColumn('user_id', 'integer', 4);
        $this->hasColumn('url', 'string', 65535);
        $this->hasColumn('logo_url', 'string', 65535);
        $this->hasColumn('forum_url', 'string', 65535);
        $this->hasColumn('reason', 'string', 255);
    }

    public function setUp() {
        $this->actAs('Timestampable');
        $this->hasOne('Category', array(
            'local' => 'category_id',
            'foreign' => 'id'
        ));
        $this->hasOne('User', array(
            'local' => 'user_id',
            'foreign' => 'id'
        ));
    }

}

Maybe I'll ask differently. What requirements has save(); function to be executed?


Undefined method stdClass::save()? - El Forum - 02-07-2010

[eluser]theprodigy[/eluser]
is 'bank' also the name of the table in your database, or is your database table something different?

EDIT:
Also, I don't see anywhere that you are instantiating the object:
Code:
$bank = new Bank();



Undefined method stdClass::save()? - El Forum - 02-08-2010

[eluser]rockstyle[/eluser]
works out now, thank you. I guess i was wrong about new instruction. Thank you Wink