本文整理汇总了PHP中Fields::parseValue方法的典型用法代码示例。如果您正苦于以下问题:PHP Fields::parseValue方法的具体用法?PHP Fields::parseValue怎么用?PHP Fields::parseValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fields
的用法示例。
在下文中一共展示了Fields::parseValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreateUpdateField
/**
* Form/submit action for adding or customizing a field.
*
* This method allows for the creation of custom fields linked to any customizable
* module in X2Engine. This is used by "Manage Fields." It is used to reload the
* form via AJAX.
*
* @param bool $search If set to 1/true, perform a lookup for an existing field
* @param bool $save If set to 1/true, attempt to save the model; otherwise just echo the form.
*/
public function actionCreateUpdateField($search = 0, $save = 0, $override = 0)
{
$changedType = false;
if ($search) {
// A field is being looked up, to populate form fields for customizing
// an existing field
$new = false;
if (isset($_POST['Fields'])) {
$model = Fields::model()->findByAttributes(array_intersect_key($_POST['Fields'], array_fill_keys(array('modelName', 'fieldName'), null)));
}
} else {
// Requesting the form
$new = true;
}
if (!isset($model) || !(bool) $model) {
// If the field model wasn't found, create the object
$model = new Fields();
}
if (isset($_POST['Fields']) && ($model->isNewRecord || $override)) {
$oldType = $model->type;
$model->attributes = $_POST['Fields'];
// field name exists if model refers to actual db record
if ($model->fieldName && $model->type !== $oldType) {
$changedType = true;
}
}
$message = '';
$error = false;
if (isset($_POST['Fields']) && $save) {
$model->attributes = $_POST['Fields'];
if (!isset($_POST['Fields']['linkType'])) {
// This can be removed if we ever make the linkType attribute more structured
// (i.e. field type-specific link type validation rules)
$model->linkType = null;
}
// Set the default value
if (isset($_POST['AmorphousModel'])) {
$aModel = $_POST['AmorphousModel'];
$model->defaultValue = $model->parseValue($aModel['customized_field']);
}
$new = $model->isNewRecord;
$model->modified = 1;
// The field has been modified
if ($new) {
// The field should be marked as custom since the user is adding it
$model->custom = 1;
}
if ($model->save()) {
$message = $new ? Yii::t('admin', 'Field added.') : Yii::t('admin', 'Field modified successfully.');
if ($new) {
$model = new Fields();
}
} else {
$error = true;
$message = Yii::t('admin', 'Please correct the following errors.');
}
}
$dummyModel = new AmorphousModel();
$dummyModel->addField($model, 'customized_field');
$dummyModel->setAttribute('customized_field', $model->defaultValue);
$this->renderPartial('createUpdateField', array('model' => $model, 'new' => $new, 'dummyModel' => $dummyModel, 'message' => $message, 'error' => $error, 'changedType' => $changedType));
}