Yii Framework Forum: Confusing Problem With Saving A Model - Help Please? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Confusing Problem With Saving A Model - Help Please? Rate Topic: -----

#1 User is offline   jakeb 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 11-March 13

Posted 17 March 2013 - 06:23 PM

Hi all, I am having some trouble with the following method in one of my Models

public function assignUserRole($user, $project, $role){
            Yii::log('into assignUserRole','info', 'models.ProjectController');
            $this->projectId = $project;
            $this->userId = $user;
            $this->role = $role;
            Yii::log('projectId= '.$this->projectId." userId = ".$this->userId." role = ".$this->role,'info', 'models.ProjectController');
            $this->dateAssigned = date(DateTime::ISO8601);
            print_r($this->errors);
             if(!$this->save()){ 
                 CVarDumper::dump($this->getErrors()); 
             }else{ return true;}
        }


The method is returning true however nothing is being saved in my DB.

the print_r($this->errors); line is just printing array( ) to my browser.

nothing of interest is being logged - here is my application log

2013/03/17 22:48:38 [info] [models.ProjectController] into assignUserRole
in /Applications/MAMP/htdocs/inkwiki/protected/models/ProjectTeam.php (106)
in /Applications/MAMP/htdocs/inkwiki/protected/controllers/InviteController.php (126)
in /Applications/MAMP/htdocs/inkwiki/index.php (13)
2013/03/17 22:48:38 [info] [models.ProjectController] projectId= 49 userId = 2 role = member
in /Applications/MAMP/htdocs/inkwiki/protected/models/ProjectTeam.php (110)
in /Applications/MAMP/htdocs/inkwiki/protected/controllers/InviteController.php (126)
in /Applications/MAMP/htdocs/inkwiki/index.php (13)


I have tried setting save(false) - this makes no difference, still get no log data and nothing is saved to the DB.

Any idea why this isn't working for me?

Thanks in advance!
0

#2 User is offline   menxaca 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 26-November 12
  • Location:Talavera de la Reina, Spain

Posted 17 March 2013 - 07:12 PM

Hi,

I would check the insert sentence, try to print it in the log, although I think if you have:

defined('YII_DEBUG') or define('YII_DEBUG',true);


in your index.php should print the sentence.

Also, are you creating the project model in somewhere else? like:
$project = new Project;

0

#3 User is offline   yugene 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 408
  • Joined: 08-August 09
  • Location:Ukraine

Posted 18 March 2013 - 05:56 AM

In addition to what is said before, I'd also check before saving the model if validation is passed,
e.g.
$this->validate();
var_dump($this->errors);

and would check model attributes, especially if record identifier is present
print_r($this->attributes);

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users