Yii - 在3个表之间保存数据

I am working with Yii and jQuery Mobile. I currently have 3 tables: Users, Projects and ShareProjects. I have been able to create a function to display shared projects with that user, but I am struggling to assign users to projects. I have tried this code but have been unsuccessful so far.

public function actionShareProjects() {  
   $model=new SharedProjects;
   if(isset($_POST['SharedProjects'])) {
      $model->attributes=$_POST['SharedProjects'];
      $model->project_id = "project_id";
      $model->user_id = "user_id";
      $model->sharedProject_id = "";
      $model->sharedCreateDate= date('Y-m-d G:i:s');
      if($model->save()) {
         echo json_encode(array('action'=>'success', 'message'=>''));
      } else {
          echo json_encode(array('action'=>'error', 'message'=>'Incorrect'));
      }
   }
}

In the project, there is a share button which takes the project id but I am trying to be able to allow the user to type an email in for the user you would like to share with.

I tried inputting it manually on postman but it failed, no errors came up but no data was saved. I used the correct input:

SharedProjects [user_id] 
SharedProjects [project_id] 
SharedProjects [sharedProject_id]
SharedProjects [sharedCreateDate]

If no error is comes up then your data is right for your model's rule validation but may be this is creating error while saving in database,

Have you applied any constraint(like unique , not null) on your table's column. They are also restrict to save wrong data in table.

change your code to this

public function actionShareProjects() {  
   $model=new SharedProjects;
   if (isset($_POST['SharedProjects'])) {
      $model->attributes=$_POST['SharedProjects'];
      $model->sharedCreateDate= date('Y-m-d H:i:s');
      if($model->save()) {
         $this->sendResponse(array('action'=>'success', 'message'=>''));
      } else {
         $this->sendResponse(array('action'=>'error', 'message'=>'Incorrect'));
      }
   }
}

and make sure project_id,user_id are set and are of int type. To play around sending JSON response better way would be adding this function

public function sendResponse($data)
{
    header('Content-Type: application/json; charset=utf-8');
    echo CJSON::encode($data);
    exit;
}

in your controller and calling it for sending response.