當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Fields::parseValue方法代碼示例

本文整理匯總了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));
 }
開發者ID:xl602,項目名稱:X2CRM,代碼行數:72,代碼來源:AdminController.php


注:本文中的Fields::parseValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。