Class kartik\grid\EditableColumnAction
Inheritance | kartik\grid\EditableColumnAction » yii\rest\Action » yii\base\Action » yii\base\Component » yii\base\BaseObject |
---|---|
Implements | yii\base\Configurable |
Available since version | 1.0 |
EditableAction is useful for processing the update of kartik\grid\EditableColumn attributes via form submission. A typical usage of this action in your controller could look like below:
// 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::class, // action class name
'modelClass' => Book::class, // 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) {}
]
]);
}
}
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$ajaxOnly | boolean | Whether to allow access to this action for AJAX requests only. | kartik\grid\EditableColumnAction |
$behaviors | yii\base\Behavior[] | List of behaviors attached to this component. | yii\base\Component |
$checkAccess | callable|null | A PHP callable that will be called when running an action to determine if the current user has the permission to execute the action. | yii\rest\Action |
$controller | yii\base\Controller|yii\web\Controller|yii\console\Controller | The controller that owns this action | yii\base\Action |
$errorMessages | array | The special error messages configuration for displaying editable submission errors other than model validation errors. | kartik\grid\EditableColumnAction |
$errorOptions | array | The options for error summary as supported by options param in yii\helpers\Html::errorSummary() |
kartik\grid\EditableColumnAction |
$findModel | callable|null | A PHP callable that will be called to return the model corresponding to the specified primary key value. | yii\rest\Action |
$formName | string | Allows overriding the form name which is used to access posted data | kartik\grid\EditableColumnAction |
$id | string | ID of the action | yii\base\Action |
$modelClass | string | Class name of the model which will be handled by this action. | yii\rest\Action |
$outputMessage | string|Closure | The output error message from the editable. | kartik\grid\EditableColumnAction |
$outputValue | string|Closure | The output value from the editable. | kartik\grid\EditableColumnAction |
$postOnly | boolean | Whether to allow access to this action for POST requests only. | kartik\grid\EditableColumnAction |
$scenario | string | The scenario to be assigned to the model before it is validated and updated. | kartik\grid\EditableColumnAction |
$showModelErrors | boolean | Whether to show model errors if outputMessage is empty or not set. |
kartik\grid\EditableColumnAction |
$uniqueId | string | The unique ID of this action among the whole application. | yii\base\Action |
Public Methods
Method | Description | Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | yii\base\BaseObject |
__clone() | This method is called after the object is created by cloning an existing one. | yii\base\Component |
__construct() | Constructor. | yii\base\Action |
__get() | Returns the value of an object property. | yii\base\BaseObject |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\BaseObject |
__set() | Sets value of an object property. | yii\base\BaseObject |
__unset() | Sets an object property to null. | yii\base\BaseObject |
attachBehavior() | Attaches a behavior to this component. | yii\base\Component |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\base\Component |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\base\Component |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\BaseObject |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\BaseObject |
className() | Returns the fully qualified name of this class. | yii\base\BaseObject |
detachBehavior() | Detaches a behavior from the component. | yii\base\Component |
detachBehaviors() | Detaches all behaviors from the component. | yii\base\Component |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\base\Component |
findModel() | Returns the data model based on the primary key given. | yii\rest\Action |
getBehavior() | Returns the named behavior object. | yii\base\Component |
getBehaviors() | Returns all behaviors attached to this component. | yii\base\Component |
getUniqueId() | Returns the unique ID of this action among the whole application. | yii\base\Action |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\base\Component |
hasMethod() | Returns a value indicating whether a method is defined. | yii\base\BaseObject |
hasProperty() | Returns a value indicating whether a property is defined. | yii\base\BaseObject |
init() | Initializes the object. | yii\rest\Action |
off() | Detaches an existing event handler from this component. | yii\base\Component |
on() | Attaches an event handler to an event. | yii\base\Component |
run() | kartik\grid\EditableColumnAction | |
runWithParams() | Runs this action with the specified parameters. | yii\base\Action |
trigger() | Triggers an event. | yii\base\Component |
Protected Methods
Method | Description | Defined By |
---|---|---|
afterRun() | This method is called right after run() is executed. |
yii\base\Action |
beforeRun() | This method is called right before run() is executed. |
yii\base\Action |
initErrorMessages() | Initializes the error messages if not set. | kartik\grid\EditableColumnAction |
parseValue() | Parses a variable if callable and computes and returns value accordingly | kartik\grid\EditableColumnAction |
validateEditable() | Validates the EditableColumn post request submission | kartik\grid\EditableColumnAction |
Property Details
Whether to allow access to this action for AJAX requests only. Defaults to true
.
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 kartik\grid\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'
.
The options for error summary as supported by options
param in yii\helpers\Html::errorSummary()
Allows overriding the form name which is used to access posted data
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.
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.
Whether to allow access to this action for POST requests only. Defaults to true
.
The scenario to be assigned to the model before it is validated and updated.
Whether to show model errors if outputMessage
is empty or not set.
Method Details
Initializes the error messages if not set.
protected void initErrorMessages ( ) |
Parses a variable if callable and computes and returns value accordingly
protected static mixed parseValue ( $var, $params = [] ) | ||
$var | mixed | The variable to be parsed |
$params | array | The function parameters if $var is callable |
public void run ( ) |
Validates the EditableColumn post request submission
protected array validateEditable ( ) | ||
return | array | The output for the Editable action response |
---|---|---|
throws | yii\web\BadRequestHttpException | |
throws | yii\base\InvalidConfigException | |
throws | yii\web\NotFoundHttpException |