本文整理汇总了PHP中GridField::setError方法的典型用法代码示例。如果您正苦于以下问题:PHP GridField::setError方法的具体用法?PHP GridField::setError怎么用?PHP GridField::setError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GridField
的用法示例。
在下文中一共展示了GridField::setError方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleAction
/**
* Handles the add action for the given DataObject.
*
* @param $gridField GridField
* @param $actionName string
* @param $arguments mixed
* @param $data array
*
* @return null|SS_HTTPResponse
*
* @throws UnexpectedValueException
*/
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
{
if ($actionName == 'add') {
$dbField = $this->getDataObjectField();
$objClass = $gridField->getModelClass();
/**
* @var DataObject $obj
*/
$obj = new $objClass();
if ($obj->hasField($dbField)) {
$obj->setCastedField($dbField, $data['gridfieldaddbydbfield'][$obj->ClassName][$dbField]);
if ($obj->canCreate()) {
$id = $gridField->getList()->add($obj);
if (!$id) {
$gridField->setError(_t('GridFieldAddByDBField.AddFail', 'Unable to save {class} to the database.', 'Unable to add the DataObject.', array('class' => get_class($obj))), 'error');
}
} else {
return Security::permissionFailure(Controller::curr(), _t('GridFieldAddByDBField.PermissionFail', 'You don\'t have permission to create a {class}.', 'Unable to add the DataObject.', array('class' => get_class($obj))));
}
} else {
throw new UnexpectedValueException(sprintf('Invalid field (%s) on %s.', $dbField, $obj->ClassName));
}
}
return null;
}
示例2: handleAction
/**
* Handles the add action for the given DataObject
*
* @param $gridFIeld GridFIeld
* @param $actionName string
* @param $arguments mixed
* @param $data array
**/
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
{
if ($actionName == "add") {
$dbField = $this->getDataObjectField();
$objClass = $gridField->getModelClass();
$obj = new $objClass();
if ($obj->hasField($dbField)) {
$obj->setCastedField($dbField, $data['gridfieldaddbydbfield'][$obj->ClassName][$dbField]);
if ($obj->canCreate()) {
$id = $gridField->getList()->add($obj);
if (!$id) {
$gridField->setError(_t("GridFieldAddByDBField.AddFail", "Unable to save {class} to the database.", "Unable to add the DataObject.", array("class" => get_class($obj))), "error");
}
} else {
return Security::permissionFailure(Controller::curr(), _t("GridFieldAddByDBField.PermissionFail", "You don't have permission to create a {class}.", "Unable to add the DataObject.", array("class" => get_class($obj))));
}
} else {
throw new UnexpectedValueException("Invalid field (" . $dbField . ") on " . $obj->ClassName . ".");
}
}
}
开发者ID:helpfulrobot,项目名称:micschk-silverstripe-filterablearchive,代码行数:29,代码来源:GridFieldAddByDBField.php
示例3: handleAction
/**
* Handles the add action for the given DataObject
*
* @param $gridFIeld GridFIeld
* @param $actionName string
* @param $arguments mixed
* @param $data array
**/
public function handleAction(GridField $gridField, $actionName, $arguments, $data)
{
if ($actionName == "add") {
// Get our submitted fields and object class
$dbField = $this->getDataObjectField();
$objClass = $gridField->getModelClass();
$source_class = $this->getSourceClass();
$filter = array();
// Has the user used autocomplete
if (isset($data['relationID']) && $data['relationID']) {
$id = $data['relationID'];
} else {
$id = null;
}
$obj = new $objClass();
// Is this a valid field
if (!$obj->hasField($dbField)) {
throw new UnexpectedValueException("Invalid field (" . $dbField . ") on " . $obj->ClassName . ".");
}
// If we have an ID try and get an existing object then
// check if we have a copy in items
if ($id) {
$source_item = $source_class::get()->byID($id);
foreach ($this->getFilterFields() as $filter_field) {
$filter[$filter_field] = $source_item->{$filter_field};
}
} else {
// Generate the filter we need to use
$string = $data['gridfieldaddbydbfield'];
foreach ($this->getFilterFields() as $filter_field) {
$filter[$filter_field] = $string;
}
}
// First check if we already have an object or if we need to
// create one
$existing_obj = $gridField->getList()->filterAny($filter)->first();
if ($existing_obj) {
$obj = $existing_obj;
}
if ($obj->ID && $obj->canEdit()) {
// An existing record and can edit, update quantity
$curr_qty = $obj->Quantity ? $obj->Quantity : 0;
$obj->setCastedField("Quantity", $curr_qty + 1);
$id = $gridField->getList()->add($obj);
}
if (!$obj->ID && $obj->canCreate()) {
// If source item not set, try and get one or get a
// an existing record
if (!$source_item) {
$source_item = $source_class::get()->filterAny($filter)->first();
}
if ($source_item) {
foreach ($this->getSourceFields() as $obj_field => $source_field) {
$obj->setCastedField($obj_field, $source_item->{$source_field});
}
} else {
$obj->setCastedField($this->getCreateField(), $string);
}
$obj->setCastedField("Quantity", 1);
$id = $gridField->getList()->add($obj);
}
if (!$id) {
$gridField->setError(_t("GridFieldAddOrderItem.AddFail", "Unable to save {class} to the database.", "Unable to add the DataObject.", array("class" => get_class($obj))), "error");
}
// Finally, issue a redirect to update totals
$controller = Controller::curr();
$response = $controller->response;
$response->addHeader('X-Pjax', 'Content');
$response->addHeader('X-Reload', true);
return $controller->redirect($gridField->getForm()->controller->Link(), 302);
}
}