本文整理汇总了PHP中Field::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Field::save方法的具体用法?PHP Field::save怎么用?PHP Field::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Field
的用法示例。
在下文中一共展示了Field::save方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
public function update()
{
$f = new Field();
$f->name = $this->getFieldName();
$f->type = $this->getFieldType();
$f->save();
$this->fieldSetup($f);
$f->save();
return $f;
}
示例2: save
/**
* Save data to the datastore.
* Manually save the map field data fragments.
**/
public function save()
{
$name = $this->get_name();
$value = $this->get_value();
// Add the "lat" meta in the database
$this->set_name($name . '-lat');
$this->set_value($value['lat']);
$this->store->save($this);
// Add the "lng" meta in the database
$this->set_name($name . '-lng');
$this->set_value($value['lng']);
$this->store->save($this);
// Add the "zoom" meta in the database
$this->set_name($name . '-zoom');
$this->set_value($value['zoom']);
$this->store->save($this);
// Add the "address" meta in the database
$this->set_name($name . '-address');
$this->set_value($value['address']);
$this->store->save($this);
// Set the value for the field
$this->set_name($name);
$field_value = !empty($value['lat']) && !empty($value['lng']) ? $value['lat'] . ',' . $value['lng'] : '';
$this->set_value($field_value);
parent::save();
}
示例3: noAudioPathDefined
/**
* Handle the case where the user removes the video or
* just doesn't specify a url path to a video
*
* @param Field $field
* @param array $input
* @return boolean
*/
protected function noAudioPathDefined($field, $input)
{
$filepath = trim($field->values->original);
if (!empty($filepath)) {
return false;
}
foreach ($this->formats as $format) {
$field->values->merge(["{$format}_url" => '']);
}
$field->json_value = $field->values->toJSON();
$field->save();
return true;
}
示例4: ___install
/**
* Install all the required fields, templates etc
*
* @access public
*
*/
public function ___install()
{
// Pin Topics / Comments Permission
if (!$this->fields->get('hbb_p_pin')) {
$field_topic_pin = new Field();
$field_topic_pin->type = $this->modules->get("FieldtypePage");
$field_topic_pin->name = 'hbb_p_pin';
$field_topic_pin->label = 'Pin Topics / Comments';
$field_topic_pin->template_id = wire('templates')->get("role")->id;
// Get the id number of the 'role' template
$field_topic_pin->labelFieldName = 'name';
$field_topic_pin->inputfield = 'InputfieldCheckboxes';
$field_topic_pin->optionColumns = 1;
$field_topic_pin->tags = 'HermodBB';
$field_topic_pin->icon = 'thumb-tack';
$field_topic_pin->save();
}
// Lock Topics Permission
if (!$this->fields->get('hbb_p_topic_lock')) {
$field_topic_lock = new Field();
$field_topic_lock->type = $this->modules->get("FieldtypePage");
$field_topic_lock->name = 'hbb_p_topic_lock';
$field_topic_lock->label = 'Lock Topics';
$field_topic_lock->template_id = wire('templates')->get("role")->id;
// Get the id number of the 'role' template
$field_topic_lock->labelFieldName = 'name';
$field_topic_lock->inputfield = 'InputfieldCheckboxes';
$field_topic_lock->optionColumns = 1;
$field_topic_lock->tags = 'HermodBB';
$field_topic_lock->icon = 'lock';
$field_topic_lock->save();
}
// View Forum Permission
if (!$this->fields->get('hbb_p_forum_view')) {
$field_forum_view = new Field();
$field_forum_view->type = $this->modules->get("FieldtypePage");
$field_forum_view->name = 'hbb_p_forum_view';
$field_forum_view->label = 'View Forum & Topics';
$field_forum_view->template_id = wire('templates')->get("role")->id;
// Get the id number of the 'role' template
$field_forum_view->labelFieldName = 'name';
$field_forum_view->inputfield = 'InputfieldCheckboxes';
$field_forum_view->optionColumns = 1;
$field_forum_view->tags = 'HermodBB';
$field_forum_view->icon = 'eye';
$field_forum_view->save();
}
// Start Topics Permission
if (!$this->fields->get('hbb_p_topic_start')) {
$field_topic_post = new Field();
$field_topic_post->type = $this->modules->get("FieldtypePage");
$field_topic_post->name = 'hbb_p_topic_start';
$field_topic_post->label = 'Start Topics';
$field_topic_post->template_id = wire('templates')->get("role")->id;
// Get the id number of the 'role' template
$field_topic_post->labelFieldName = 'name';
$field_topic_post->inputfield = 'InputfieldCheckboxes';
$field_topic_post->optionColumns = 1;
$field_topic_post->tags = 'HermodBB';
$field_topic_post->icon = 'file';
$field_topic_post->save();
}
// View Comments Permission
if (!$this->fields->get('hbb_p_comments_view')) {
$field_comments_view = new Field();
$field_comments_view->type = $this->modules->get("FieldtypePage");
$field_comments_view->name = 'hbb_p_comments_view';
$field_comments_view->label = 'View Comments (replies)';
$field_comments_view->template_id = wire('templates')->get("role")->id;
// Get the id number of the 'role' template
$field_comments_view->labelFieldName = 'name';
$field_comments_view->inputfield = 'InputfieldCheckboxes';
$field_comments_view->optionColumns = 1;
$field_comments_view->tags = 'HermodBB';
$field_comments_view->icon = 'eye';
$field_comments_view->save();
}
// Post Comments Permission
if (!$this->fields->get('hbb_p_comments_post')) {
$field_comments_post = new Field();
$field_comments_post->type = $this->modules->get("FieldtypePage");
$field_comments_post->name = 'hbb_p_comments_post';
$field_comments_post->label = 'Post Comments (replies)';
$field_comments_post->template_id = wire('templates')->get("role")->id;
// Get the id number of the 'role' template
$field_comments_post->labelFieldName = 'name';
$field_comments_post->inputfield = 'InputfieldCheckboxes';
$field_comments_post->optionColumns = 1;
$field_comments_post->tags = 'HermodBB';
$field_comments_post->icon = 'comment';
$field_comments_post->save();
}
// Forum Description
if (!$this->fields->get('hbb_forum_description')) {
//.........这里部分代码省略.........
示例5: install
public function install(array $settings)
{
$field = $this->fields->get('email_images');
if (!$field) {
$field = new Field();
$field->name = 'email_images';
$field->type = $this->modules->get('FieldtypeImage');
$field->label = 'Email Images';
$field->extensions = 'jpeg jpg gif png';
$field->maxFiles = 0;
$field->unzip = 0;
$field->descriptionRows = 1;
$field->entityEncode = 1;
$field->save();
$this->message("Created field: {$field->name}");
}
$settings['images_field_id'] = $field->id;
$field2 = $this->fields->get('email_image_body');
if (!$field2) {
$field2 = new Field();
$field2->name = 'email_image_body';
$field2->type = $this->modules->get('FieldtypeTextarea');
$field2->label = 'Body Text';
$field2->textformatters = array('TextformatterEntities');
$field2->inputfieldClass = 'InputfieldTextarea';
$field2->rows = 5;
$field2->save();
$this->message("Created field: {$field2->name}");
}
// parent fieldgroup
$parentFieldgroup = $this->fieldgroups->get('email-images');
if (!$parentFieldgroup) {
$parentFieldgroup = new Fieldgroup();
$parentFieldgroup->name = 'email-images';
$parentFieldgroup->save();
$parentFieldgroup->add('title');
$parentFieldgroup->save();
$this->message("Created fieldgroup: {$parentFieldgroup->name}");
}
// parent template
$parentTemplate = $this->templates->get('email-images');
if (!$parentTemplate) {
$parentTemplate = new Template();
$parentTemplate->name = 'email-images';
$parentTemplate->fieldgroup = $parentFieldgroup;
$parentTemplate->allowPageNum = 1;
$parentTemplate->save();
$this->message("Created template: {$parentTemplate->name}");
}
$settings['parent_template_id'] = $parentTemplate->id;
// child fieldgroup
$childFieldgroup = $this->fieldgroups->get('email-image');
if (!$childFieldgroup) {
$childFieldgroup = new Fieldgroup();
$childFieldgroup->name = 'email-image';
$childFieldgroup->save();
$childFieldgroup->add('title');
$childFieldgroup->add($field);
// email_images
$childFieldgroup->add($field2);
// email_image_body
$childFieldgroup->save();
$this->message("Created fieldgroup: {$childFieldgroup->name}");
}
// child template
$childTemplate = $this->templates->get('email-image');
if (!$template) {
$childTemplate = new Template();
$childTemplate->name = 'email-image';
$childTemplate->fieldgroup = $childFieldgroup;
$childTemplate->noChildren = 1;
$childTemplate->parentTemplates = array($parentTemplate->id);
$childTemplate->save();
$this->message("Created template: {$childTemplate->name}");
}
$settings['child_template_id'] = $childTemplate->id;
$parentPage = $this->pages->get('/email-images/');
if (!$parentPage->id) {
$parentPage = new Page();
$parentPage->template = $parentTemplate;
$parentPage->parent = '/';
$parentPage->name = 'email-images';
$parentPage->title = 'Email Images';
$parentPage->addStatus(Page::statusHidden);
$parentPage->sortfield = '-created';
$parentPage->save();
$this->message("Created page: {$parentPage->path}");
}
$settings['parent_page_id'] = $parentPage->id;
// update settings for parentTemplate
$parentTemplate->childTemplates = array($childTemplate->id);
$parentTemplate->noParents = 1;
$parentTemplate->save();
$this->modules->saveModuleConfigData('EmailImage', $settings);
// install template file
if (is_writable(wire('config')->paths->templates)) {
if (@copy(dirname(__FILE__) . '/email-images.php', wire('config')->paths->templates . 'email-images.php')) {
$this->message("Installed template file: email-images.php");
}
}
//.........这里部分代码省略.........
示例6: ___install
/**
* Install the module and related modules
*
*/
public function ___install()
{
$configData = array();
if ($this->templates->get(LanguageSupport::languageTemplateName)) {
throw new WireException("There is already a template installed called 'language'");
}
if ($this->fields->get(LanguageSupport::languageFieldName)) {
throw new WireException("There is already a field installed called 'language'");
}
$adminPage = $this->pages->get($this->config->adminRootPageID);
$setupPage = $adminPage->child("name=setup");
if (!$setupPage->id) {
throw new WireException("Unable to locate {$adminPage->path}setup/");
}
// create the languages parent page
$languagesPage = new Page();
$languagesPage->parent = $setupPage;
$languagesPage->template = $this->templates->get('admin');
$languagesPage->process = $this->modules->get('ProcessLanguage');
// INSTALL ProcessLanguage module
$this->message("Installed ProcessLanguage");
$languagesPage->name = 'languages';
$languagesPage->title = 'Languages';
$languagesPage->status = Page::statusSystem;
$languagesPage->sort = $setupPage->numChildren;
$languagesPage->save();
$configData['languagesPageID'] = $languagesPage->id;
// create the 'language_files' field used by the 'language' fieldgroup
$field = new Field();
$field->type = $this->modules->get("FieldtypeFile");
$field->name = 'language_files';
$field->label = 'Language Translation Files';
$field->extensions = 'json';
$field->maxFiles = 0;
$field->inputfieldClass = 'InputfieldFile';
$field->unzip = 1;
$field->descriptionRows = 1;
$field->flags = Field::flagSystem | Field::flagPermanent;
$field->save();
$this->message("Created field: language_files");
// create the fieldgroup to be used by the language template
$fieldgroup = new Fieldgroup();
$fieldgroup->name = LanguageSupport::languageTemplateName;
$fieldgroup->add($this->fields->get('title'));
$fieldgroup->add($field);
// language_files
$fieldgroup->save();
$this->message("Created fieldgroup: " . LanguageSupport::languageTemplateName . " ({$fieldgroup->id})");
// create the template used by Language pages
$template = new Template();
$template->name = LanguageSupport::languageTemplateName;
$template->fieldgroup = $fieldgroup;
$template->parentTemplates = array($adminPage->template->id);
$template->slashUrls = 1;
$template->pageClass = 'Language';
$template->pageLabelField = 'name';
$template->noGlobal = 1;
$template->noMove = 1;
$template->noTrash = 1;
$template->noUnpublish = 1;
$template->noChangeTemplate = 1;
$template->nameContentTab = 1;
$template->flags = Template::flagSystem;
$template->save();
$this->message("Created Template: " . LanguageSupport::languageTemplateName);
// create the default language page
$default = new Language();
$default->template = $template;
$default->parent = $languagesPage;
$default->name = 'default';
$default->title = 'Default';
$default->status = Page::statusSystem;
$default->save();
$configData['defaultLanguagePageID'] = $default->id;
$configData['otherLanguagePageIDs'] = array();
// non-default language IDs placeholder
$this->message("Created Default Language Page: {$default->path}");
// create the translator page and process
$translatorPage = new Page();
$translatorPage->parent = $setupPage;
$translatorPage->template = $this->templates->get('admin');
$translatorPage->status = Page::statusHidden | Page::statusSystem;
$translatorPage->process = $this->modules->get('ProcessLanguageTranslator');
// INSTALL ProcessLanguageTranslator
$this->message("Installed ProcessLanguageTranslator");
$translatorPage->name = 'language-translator';
$translatorPage->title = 'Language Translator';
$translatorPage->save();
$configData['languageTranslatorPageID'] = $translatorPage->id;
$this->message("Created Language Translator Page: {$translatorPage->path}");
// save the module config data
$this->modules->saveModuleConfigData('LanguageSupport', $configData);
// install 'language' field that will be added to the user fieldgroup
$field = new Field();
$field->type = $this->modules->get("FieldtypePage");
$field->name = LanguageSupport::languageFieldName;
//.........这里部分代码省略.........
示例7: ___processImport
/**
* Commit changed field data
*
*/
protected function ___processImport()
{
$data = $this->session->get('FieldImportData');
if (!$data) {
throw new WireException("Invalid import data");
}
$numChangedFields = 0;
$numAddedFields = 0;
$skipFieldNames = array();
// iterate through data for each field
foreach ($data as $name => $fieldData) {
$name = $this->wire('sanitizer')->fieldName($name);
if (!$this->input->post("import_field_{$name}")) {
$skipFieldNames[] = $name;
unset($data[$name]);
continue;
}
$field = $this->wire('fields')->get($name);
if (!$field) {
$new = true;
$field = new Field();
$field->name = $name;
} else {
$new = false;
}
unset($fieldData['id']);
foreach ($fieldData as $property => $value) {
if (!in_array($property, $this->input->post("field_{$name}"))) {
unset($fieldData[$property]);
}
}
try {
$changes = $field->setImportData($fieldData);
foreach ($changes as $key => $info) {
$this->message($this->_('Saved:') . " {$name}.{$key} => {$info['new']}");
}
$field->save();
if ($new) {
$numAddedFields++;
$this->message($this->_('Added field') . ' - ' . $name);
} else {
$numChangedFields++;
$this->message($this->_('Modified field') . ' - ' . $name);
}
} catch (Exception $e) {
$this->error($e->getMessage());
}
$data[$name] = $fieldData;
}
$this->session->set('FieldImportSkipNames', $skipFieldNames);
$this->session->set('FieldImportData', $data);
$numSkippedFields = count($skipFieldNames);
if ($numAddedFields) {
$this->message(sprintf($this->_n('Added %d field', 'Added %d fields', $numAddedFields), $numAddedFields));
}
if ($numChangedFields) {
$this->message(sprintf($this->_n('Modified %d field', 'Modified %d fields', $numChangedFields), $numChangedFields));
}
if ($numSkippedFields) {
$this->message(sprintf($this->_n('Skipped %d field', 'Skipped %d fields', $numSkippedFields), $numSkippedFields));
}
$this->session->redirect("./?verify=1");
}
示例8: executeSaveField
/**
* Create a new field and save it to database
* @param sfWebRequest $request
* @return <type>
*/
public function executeSaveField(sfWebRequest $request) {
$data = $request->getPostParameters();
$fieldClass = new FieldClass();
$data = $fieldClass->prepareSaveData($data); // prepare the data to save, set color and writeprotected flag
// create parent element for the fields
$fieldObj = new Field();
$fieldObj->setTitle($data['createFileWindow_fieldname']);
$fieldObj->setType($data['createFileWindow_fieldtype']);
$fieldObj->setwriteprotected($data['createFileWindow_writeprotected']);
$fieldObj->setColor($data['createFileWindow_color']);
$fieldObj->save();
$id = $fieldObj->getId();
// add the child elements to the field, with the selected field type
switch ($data['createFileWindow_fieldtype']) {
case 'TEXTFIELD':
$textfield = new FieldTextfield();
$textfield->setFieldId($id);
$textfield->setRegex($data['fieldTextfield_regularexpression']);
$textfield->setDefaultvalue($data['fieldTextfield_standard']);
$textfield->save();
break;
case 'CHECKBOX':
// do nothing
break;
case 'NUMBER':
$numberfield = new FieldNumber();
$numberfield->setRegex($data['fieldNumber_regularexpression']);
$numberfield->setDefaultvalue($data['fieldNumber_standard']);
$numberfield->setComboboxvalue($data['fieldNumber_regularexpressioncombo']);
$numberfield->setFieldId($id);
$numberfield->save();
break;
case 'DATE':
$datefield = new FieldDate();
$datefield->setRegex($data['fieldDate_regularexpression']);
$datefield->setDateformat($data['fieldDate_format']);
$datefield->setDefaultvalue($data['fieldDate_date']);
$datefield->setFieldId($id);
$datefield->save();
break;
case 'TEXTAREA':
$data['fieldTextarea_content'] = $data['fieldTextarea_contenttype'] == 'plain' ? $data['fieldTextarea_textarea']: $data['fieldTextarea_htmlarea'];
$textarea = new FieldTextarea();
$textarea->setContent($data['fieldTextarea_content']);
$textarea->setContenttype($data['fieldTextarea_contenttype']);
$textarea->setFieldId($id);
$textarea->save();
break;
case 'RADIOGROUP':
$fieldClass->saveRadiogroup($id, $data); // save radiogroup
break;
case 'CHECKBOXGROUP':
$fieldClass->saveCheckboxgroup($id, $data); // save checkboxgroup
break;
case 'COMBOBOX':
$fieldClass->saveCombobox($id, $data); // save combobox
break;
case 'FILE':
$file = new FieldFile();
$file->setRegex($data['fieldFile_regularexpression']);
$file->setFieldId($id);
$file->save();
break;
}
$this->renderText('{success:true}');
return sfView::NONE;
}
示例9: createIfNotExists
/**
* Get or create field if not exists
*
* @param int $category_id
* @param string $fieldName
* @return \Field
*/
public function createIfNotExists($category_id, $fieldName, $createAttributes = array())
{
$field = Field::model()->findSingleByAttributes(array('category_id' => $category_id, 'name' => $fieldName));
if (!$field) {
$field = new Field();
$field->setAttributes($createAttributes, false);
$field->category_id = $category_id;
$field->name = $fieldName;
$field->save();
}
return $field;
}
示例10: addFilesFields
public function addFilesFields($fieldgroup)
{
// create the 'language_files_site' field used by the 'language' fieldgroup
$field = $this->wire('fields')->get('language_files_site');
if (!$field) {
$field = new Field();
$field->type = $this->modules->get("FieldtypeFile");
$field->name = 'language_files_site';
$field->label = 'Site Translation Files';
$field->extensions = 'json';
$field->maxFiles = 0;
$field->inputfieldClass = 'InputfieldFile';
$field->unzip = 1;
$field->flags = Field::flagSystem | Field::flagPermanent;
$field->save();
$this->message("Created field: language_files_site");
}
// update
$field->label = 'Site Translation Files';
$field->description = 'Use this for field for translations specific to your site (like files in /site/templates/ for example).';
$field->descriptionRows = 0;
$field->save();
$fieldgroup->add($field);
// create the 'language_files' field used by the 'language' fieldgroup
$field = $this->wire('fields')->get('language_files');
if (!$field) {
$field = new Field();
$field->type = $this->modules->get("FieldtypeFile");
$field->name = 'language_files';
$field->label = 'Core Translation Files';
$field->extensions = 'json';
$field->maxFiles = 0;
$field->inputfieldClass = 'InputfieldFile';
$field->unzip = 1;
$field->flags = Field::flagSystem | Field::flagPermanent;
$field->save();
$this->message("Created field: language_files");
}
// update
$field->label = 'Core Translation Files';
$field->description = 'Use this for field for [language packs](http://modules.processwire.com/categories/language-pack/). To delete all files, double-click the trash can for any file, then save.';
$field->descriptionRows = 0;
$field->save();
$fieldgroup->add($field);
$fieldgroup->save();
}
示例11: ___install
/**
* Install the admin theme
*
* Other admin themes using an install() method must call this install before their own.
*
*/
public function ___install()
{
// if we are the only admin theme installed, no need to add an admin_theme field
if (self::$numAdminThemes == 0) {
return;
}
// install a field for selecting the admin theme from the user's profile
$field = $this->wire('fields')->get('admin_theme');
$toUseNote = $this->_('To use this theme, select it from your user profile.');
// we already have this field installed, no need to continue
if ($field) {
$this->message($toUseNote);
return;
}
// this will be the 2nd admin theme installed, so add a field that lets them select admin theme
$field = new Field();
$field->name = 'admin_theme';
$field->type = $this->wire('modules')->get('FieldtypeModule');
$field->set('moduleTypes', array('AdminTheme'));
$field->set('labelField', 'title');
$field->set('inputfieldClass', 'InputfieldRadios');
$field->label = 'Admin Theme';
$field->flags = Field::flagSystem;
$field->save();
$fieldgroup = $this->wire('fieldgroups')->get('user');
$fieldgroup->add($field);
$fieldgroup->save();
// make this field one that the user is allowed to configure in their profile
$data = $this->wire('modules')->getModuleConfigData('ProcessProfile');
$data['profileFields'][] = 'admin_theme';
$this->wire('modules')->saveModuleConfigData('ProcessProfile', $data);
$this->message($this->_('Installed field "admin_theme" and added to user profile settings.'));
$this->message($toUseNote);
}