Hi, i am trying to create a follow system to users. I created crud and it works ok. Now i am trying to add a follow button to user profile with pjax but it gives internal server error.
Nope, it is not bracket, i solved it but thanks for reply anyway.
The problem is user form, follow model conflict. I created active form in user view.php, so it created a form which uses user ids for fileds (not follow ids). But in controller.php i tried to load these user ided fields to follow model so it gives the error. For example the iput id must be “follow-followid” but active form created “user-followid” automatically.
I customized the submit form as follow form and now it works.
Now i have a new question. I did not use JSON for return data, because it returns only string and i want to return html tags in container which reloads with this cod $.pjax.reload({container:"#follows"});
public function actionAddfollow() {
//Yii::$app->response->format = Response::FORMAT_JSON;
$model = new Follow();
$model->load(Yii::$app->request->post());
$model->fid =Yii::$app->user->identity->id;
if (!Follow::findOne(['fid' => $model->fid,'uid' => $model->uid,])){
if ($model->save()) {
return '<i class="fa-check-circle"></i> Following';
}else {
return '<i class="fa-times-circle"></i> Failed';
}
}
}