PHP 클래스 kartik\grid\EditableColumnAction

php you can set the EditableColumn::editableOptions['formOptions']['action'] to point to the action below i.e. /site/editbook for the example below use kartik\grid\EditableColumnAction; use yii\web\Controller; use yii\helpers\ArrayHelper; use app\models\Book; class SiteController extends Controller { public function actions() { return array_replace_recursive(parent::actions(), [ 'editbook' => [ // identifier for your editable column action 'class' => EditableColumnAction::className(), // action class name 'modelClass' => Book::className(), // the model for the record being edited 'scenario' => Model::SCENARIO_DEFAULT, // model scenario assigned before validation & update 'outputValue' => function ($model, $attribute, $key, $index) { return (int) $model->$attribute / 100; // return a calculated output value if desired }, 'outputMessage' => function($model, $attribute, $key, $index) { return ''; // any custom error to return after model save }, 'showModelErrors' => true, // show model validation errors after save 'errorOptions' => ['header' => ''] // error summary HTML options 'postOnly' => true, 'ajaxOnly' => true, 'findModel' => function($id, $action) }, 'checkAccess' => function($action, $model) } ] ]); } }
부터: 1.0
저자: Kartik Visweswaran ([email protected])
상속: extends yii\rest\Action
파일 보기 프로젝트 열기: kartik-v/yii2-grid 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$ajaxOnly whether to allow access to this action for AJAX requests only. Defaults to true.
$errorMessages the special error messages configuration for displaying editable submission errors other than model validation errors. The following keys can be set to configure the relevant error messages: - invalidEditable: _string_, the message to be displayed when this action has not been used with the EditableColumn or no value for $_POST[hasEditable] is detected over post request. If not set, this will default to the i18n translated string: 'Invalid or bad editable data'. - invalidModel: _string_, the message to be displayed when no valid model has been found for the editable primary key submitted over post request. If not set will default to the i18n translated string: 'No valid editable model found'. - editableException: _string_, the message to be displayed when an invalid editable index or model form name is available over post request. If not set will default to the i18n translated string: 'Invalid editable index or model form name'. - saveException: _string_, the message to be displayed for any unknown server or database exception when saving the model data and when no model errors are found. If not set will default to the i18n translated string: 'Failed to update editable data due to an unknown server error'.
$errorOptions the options for error summary as supported by options param in yii\helpers\Html::errorSummary()
$formName allows overriding the form name which is used to access posted data
$outputMessage the output error message from the editable. If set as a string, will be returned as is. If set as a [[Closure]], the signature of the callback would be function ($model, $attribute, $key, $index) { }, where: - $model: _\yii\base\Model_, is the model data retrieved via POST. - $attribute: _string_, the attribute name for which the editable plugin is initialized. - $key: _mixed_, is the model primary key value. - $index: _integer_, is the zero-based index of the data model among the model array returned by [[dataProvider]].
$outputValue the output value from the editable. If set as a string, will be returned as is. If set as a [[Closure]], the signature of the callback would be function ($model, $attribute, $key, $index) { }, where: - $model: _\yii\base\Model_, is the model data retrieved via POST. - $attribute: _string_, the attribute name for which the editable plugin is initialized. - $key: _mixed_, is the model primary key value. - $index: _integer_, is the zero-based index of the data model among the model array returned by [[dataProvider]].
$postOnly whether to allow access to this action for POST requests only. Defaults to true.
$scenario the scenario to be assigned to the model before it is validated and updated.
$showModelErrors whether to show model errors if outputMessage is empty or not set.

공개 메소드들

메소드 설명
run ( )

보호된 메소드들

메소드 설명
initErrorMessages ( ) Initializes the error messages if not set.
parseValue ( mixed $var, array $params = [] ) : mixed Parses a variable if callable and computes and returns value accordingly
validateEditable ( ) : array Validates the EditableColumn post request submission

메소드 상세

initErrorMessages() 보호된 메소드

Initializes the error messages if not set.
protected initErrorMessages ( )

parseValue() 보호된 정적인 메소드

Parses a variable if callable and computes and returns value accordingly
protected static parseValue ( mixed $var, array $params = [] ) : mixed
$var mixed the variable to be parsed
$params array the function parameters if $var is callable
리턴 mixed

run() 공개 메소드

public run ( )

validateEditable() 보호된 메소드

Validates the EditableColumn post request submission
protected validateEditable ( ) : array
리턴 array the output for the Editable action response

프로퍼티 상세

$ajaxOnly 공개적으로 프로퍼티

whether to allow access to this action for AJAX requests only. Defaults to true.
public $ajaxOnly

$errorMessages 공개적으로 프로퍼티

the special error messages configuration for displaying editable submission errors other than model validation errors. The following keys can be set to configure the relevant error messages: - invalidEditable: _string_, the message to be displayed when this action has not been used with the EditableColumn or no value for $_POST[hasEditable] is detected over post request. If not set, this will default to the i18n translated string: 'Invalid or bad editable data'. - invalidModel: _string_, the message to be displayed when no valid model has been found for the editable primary key submitted over post request. If not set will default to the i18n translated string: 'No valid editable model found'. - editableException: _string_, the message to be displayed when an invalid editable index or model form name is available over post request. If not set will default to the i18n translated string: 'Invalid editable index or model form name'. - saveException: _string_, the message to be displayed for any unknown server or database exception when saving the model data and when no model errors are found. If not set will default to the i18n translated string: 'Failed to update editable data due to an unknown server error'.
public $errorMessages

$errorOptions 공개적으로 프로퍼티

the options for error summary as supported by options param in yii\helpers\Html::errorSummary()
public $errorOptions

$formName 공개적으로 프로퍼티

allows overriding the form name which is used to access posted data
public $formName

$outputMessage 공개적으로 프로퍼티

the output error message from the editable. If set as a string, will be returned as is. If set as a [[Closure]], the signature of the callback would be function ($model, $attribute, $key, $index) { }, where: - $model: _\yii\base\Model_, is the model data retrieved via POST. - $attribute: _string_, the attribute name for which the editable plugin is initialized. - $key: _mixed_, is the model primary key value. - $index: _integer_, is the zero-based index of the data model among the model array returned by [[dataProvider]].
public $outputMessage

$outputValue 공개적으로 프로퍼티

the output value from the editable. If set as a string, will be returned as is. If set as a [[Closure]], the signature of the callback would be function ($model, $attribute, $key, $index) { }, where: - $model: _\yii\base\Model_, is the model data retrieved via POST. - $attribute: _string_, the attribute name for which the editable plugin is initialized. - $key: _mixed_, is the model primary key value. - $index: _integer_, is the zero-based index of the data model among the model array returned by [[dataProvider]].
public $outputValue

$postOnly 공개적으로 프로퍼티

whether to allow access to this action for POST requests only. Defaults to true.
public $postOnly

$scenario 공개적으로 프로퍼티

the scenario to be assigned to the model before it is validated and updated.
public $scenario

$showModelErrors 공개적으로 프로퍼티

whether to show model errors if outputMessage is empty or not set.
public $showModelErrors