php - Yii - Saving Data between 3 tables -
i working yii , jquery mobile. have 3 tables: users, projects , shareprojects. have been able create function display shared projects user, struggling assign users projects. have tried code have been unsuccessful 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 project, there share button takes project id trying able allow user type email in user share with.
i tried inputting manually on postman failed, no errors came no data saved. used correct input:
sharedprojects [user_id] sharedprojects [project_id] sharedprojects [sharedproject_id] sharedprojects [sharedcreatedate]
change code 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
set , of int
type. play around sending json
response better way adding function
public function sendresponse($data) { header('content-type: application/json; charset=utf-8'); echo cjson::encode($data); exit; }
in controller , calling sending response.
This comment has been removed by the author.
ReplyDelete