How to use Editable in Yii2 on DetailView

Follow to get in your Yii2 project

Add on the top of your page in yii2 view.

use kartik\editable\Editable;
// create a similar in your code replace ‘name’ with you correct attribute
‘model’=> $model,
‘displayValueConfig’=> $model->name,
‘data’=>$model->name, // any list of values
// in your controller for that model add the following code
// Check if there is an Editable ajax request
if (isset($_POST[‘hasEditable’])) {
// use Yii’s response format to encode output as JSON
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
// read your posted model attributes
if ($model->load($_POST)) {
$redirectFlag = false;
$output = ”;
$posted = $_POST[‘Projects’]; // <———– This is your Model NAME
if( isset($posted[‘name’]) AND!empty($posted[‘name’]) ){
$model->name = $posted[‘name’];
$redirectFlag = true; //set to true to reload the page to update non ajax content
if($redirectFlag){return$this->redirect([‘view’, ‘id’=> $model->project_id]);
}else{return [‘output’=>$output, ‘message’=>”]; }
}else{return [‘output’=>”, ‘message’=>’Validation error’]; }
}else {return [‘output’=>”, ‘message’=>”];}