当前位置: 首页>>代码示例>>PHP>>正文


PHP Lang::exists方法代码示例

本文整理汇总了PHP中Lang::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Lang::exists方法的具体用法?PHP Lang::exists怎么用?PHP Lang::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lang的用法示例。


在下文中一共展示了Lang::exists方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: edit

 /**
  * Edit a role
  */
 public function edit()
 {
     $param = array('id' => 'edit-role-form', 'model' => 'Role', 'reference' => array('id' => $this->roleId), 'fieldsets' => array('form' => array('nofieldset' => true, new HiddenInput(array('field' => 'removable', 'default' => 1, 'readonly' => true)), new TextInput(array('field' => 'name', 'maxlength' => 32, 'label' => Lang::get('roles.form-name-label'), 'required' => true)), new ColorInput(array('field' => 'color', 'label' => Lang::get('roles.form-color-label'), 'default' => '#000'))), '_submits' => array(new SubmitInput(array('name' => 'valid', 'value' => Lang::get('main.valid-button'))), new DeleteInput(array('name' => 'delete', 'value' => Lang::get('main.delete-button'), 'notDisplayed' => $this->roleId == -1)), new ButtonInput(array('name' => 'cancel', 'value' => Lang::get('main.cancel-button'), 'onclick' => 'app.dialog("close")')))), 'onsuccess' => 'app.dialog("close"); app.load(app.getUri("list-roles"), {selector : "#admin-roles-tab"});');
     foreach (Language::getAll() as $language) {
         $param['fieldsets']['form'][] = new TextInput(array('name' => "translation[{$language->tag}]", "independant" => true, 'required' => $language->tag == LANGUAGE, "label" => Lang::get("roles.role-label-label", array('lang' => $language->tag)), "default" => Lang::exists("roles.role-" . $this->roleId . "-label") ? Lang::get("roles.role-" . $this->roleId . "-label", array(), 0, $language->tag) : ''));
     }
     $form = new Form($param);
     if (!$form->submitted()) {
         return View::make(Theme::getSelected()->getView("dialogbox.tpl"), array('icon' => 'user', 'title' => Lang::get('roles.form-title'), 'page' => $form));
     } else {
         if ($form->submitted() == "delete") {
             $form->delete(Form::NO_EXIT);
             if ($key) {
                 $key->delete();
             }
             return $form->response(Form::STATUS_SUCCESS);
         } else {
             if ($form->check()) {
                 try {
                     $roleId = $form->register(Form::NO_EXIT);
                     // Create the language key for the translations of the role name
                     foreach (App::request()->getBody('translation') as $tag => $translation) {
                         Language::getByTag($tag)->saveTranslations(array('roles' => array("role-{$roleId}-label" => $translation)));
                     }
                     return $form->response(Form::STATUS_SUCCESS);
                 } catch (Exception $e) {
                     return $form->response(Form::STATUS_ERROR, DEBUG_MODE ? $e->getMessage() : "");
                 }
             }
         }
     }
 }
开发者ID:elvyrra,项目名称:hawk,代码行数:35,代码来源:RoleController.php

示例2: onAfterDispatch

 /**
  * This method adds alternate meta tags for associated menu items
  *
  * @return	nothing
  * @since	1.7
  */
 public function onAfterDispatch()
 {
     if (App::isSite() && $this->params->get('alternate_meta') && Document::getType() == 'html') {
         // Get active menu item
         $active = App::get('menu')->getActive();
         if (!$active) {
             return;
         }
         // Get menu item link
         if (Config::get('sef')) {
             $active_link = Route::url('index.php?Itemid=' . $active->id, false);
         } else {
             $active_link = Route::url($active->link . '&Itemid=' . $active->id, false);
         }
         if ($active_link == JUri::base(true) . '/') {
             $active_link .= 'index.php';
         }
         // Get current link
         $current_link = Request::getUri();
         if ($current_link == Request::base(true) . '/') {
             $current_link .= 'index.php';
         }
         // Check the exact menu item's URL
         if ($active_link == $current_link) {
             // Get menu item associations
             JLoader::register('MenusHelper', PATH_CORE . '/components/com_menus/admin/helpers/menus.php');
             $associations = MenusHelper::getAssociations($active->id);
             // Remove current menu item
             unset($associations[$active->language]);
             // Associated menu items in other languages
             if ($associations && $this->params->get('menu_associations')) {
                 $menu = App::get('menu');
                 $server = JURI::getInstance()->toString(array('scheme', 'host', 'port'));
                 foreach (JLanguageHelper::getLanguages() as $language) {
                     if (isset($associations[$language->lang_code])) {
                         $item = $menu->getItem($associations[$language->lang_code]);
                         if ($item && Lang::exists($language->lang_code)) {
                             if (Config::get('sef')) {
                                 $link = Route::url('index.php?Itemid=' . $associations[$language->lang_code] . '&lang=' . $language->sef);
                             } else {
                                 $link = Route::url($item->link . '&Itemid=' . $associations[$language->lang_code] . '&lang=' . $language->sef);
                             }
                             // Check if language is the default site language and remove url language code is on
                             if ($language->sef == self::$default_sef && $this->params->get('remove_default_prefix') == '1') {
                                 $relLink = preg_replace('|/' . $language->sef . '/|', '/', $link, 1);
                                 Document::addHeadLink($server . $relLink, 'alternate', 'rel', array('hreflang' => $language->lang_code));
                             } else {
                                 Document::addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code));
                             }
                         }
                     }
                 }
             } elseif ($active->home) {
                 $menu = App::get('menu');
                 $server = JURI::getInstance()->toString(array('scheme', 'host', 'port'));
                 foreach (JLanguageHelper::getLanguages() as $language) {
                     $item = $menu->getDefault($language->lang_code);
                     if ($item && $item->language != $active->language && $item->language != '*' && JLanguage::exists($language->lang_code)) {
                         if (Config::get('sef')) {
                             $link = Route::url('index.php?Itemid=' . $item->id . '&lang=' . $language->sef);
                         } else {
                             $link = Route::url($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef);
                         }
                         // Check if language is the default site language and remove url language code is on
                         if ($language->sef == self::$default_sef && $this->params->get('remove_default_prefix') == '1') {
                             $relLink = preg_replace('|/' . $language->sef . '/|', '/', $link, 1);
                             Document::addHeadLink($server . $relLink, 'alternate', 'rel', array('hreflang' => $language->lang_code));
                         } else {
                             Document::addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code));
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:mined-gatech,项目名称:hubzero-cms,代码行数:82,代码来源:languagefilter.php

示例3: check

 /**
  * Check the submitted value of the input
  *
  * @param Form $form The form the input is associated with
  *
  * @return bool True if the submitted value is valid, else false
  */
 public function check(&$form = null)
 {
     if (empty($this->errorAt)) {
         $this->errorAt = $this->name;
     }
     // Check, if the field is required, that a value was submitted
     if (!empty($this->required) && ((string) $this->value == '' || $this->emptyValue && $this->value === $this->emptyValue)) {
         // The field is required but not filled
         $form && $form->error($this->errorAt, Lang::get('form.required-field'));
         return false;
     }
     // Check the format of the field is correct
     if (!empty($this->value) && !empty($this->pattern)) {
         // test the format of the field
         if (!preg_match($this->pattern, $this->value)) {
             // the format of the field value is not correct
             if ($form) {
                 $message = '';
                 if (isset($this->errorMessage)) {
                     $message = $this->errorMessage;
                 } elseif (Lang::exists('form.' . static::TYPE . "-format")) {
                     $message = Lang::get('form.' . static::TYPE . "-format");
                 } else {
                     $message = Lang::get('form.field-format');
                 }
                 $form->error($this->errorAt, $message);
             }
             return false;
         }
     }
     // If the value of this field must be unique in the database, check this unicity is not compromised
     if (!empty($this->value) && $this->unique && $form) {
         $example = array(array($this->name => $this->dbvalue()));
         if ($form->object) {
             $example['$not'] = $form->reference;
         }
         $example = new DBExample($example);
         $model = $form->model;
         if ($model::getByExample($example)) {
             // The field must be unique but is not
             $form->error($this->errorAt, Lang::get('form.unique-field'));
             return false;
         }
     }
     // Check custom validators
     if (!empty($this->validators)) {
         foreach ($this->validators as $validator) {
             $error = '';
             if (is_callable($validator) && !$validator($this, $error)) {
                 $form->error($this->errorAt, $error);
                 return false;
             }
         }
     }
     // The field is correctly filled (for the common checks)
     return true;
 }
开发者ID:elvyrra,项目名称:hawk,代码行数:64,代码来源:FormInput.php

示例4: addKey

 /**
  * Add a new language key
  */
 public function addKey()
 {
     $form = $this->keyForm();
     if ($form->check()) {
         try {
             $key = self::DEFAULT_KEY_PLUGIN . '.' . $form->getData('key');
             if (Lang::exists($key)) {
                 $form->error('key', Lang::get('language.key-already-exists'));
                 return $form->response(Form::STATUS_CHECK_ERROR);
             }
             foreach (Language::getAll() as $language) {
                 $translation = $form->getData("translation[{$language->tag}]");
                 if ($translation) {
                     $language->saveTranslations(array(self::DEFAULT_KEY_PLUGIN => array($form->getData('key') => $translation)));
                 }
             }
             App::logger()->info('A new language key has been added');
             return $form->response(Form::STATUS_SUCCESS);
         } catch (Exception $e) {
             App::logger()->error('An error occured while adding a language key : ' . $e->getMessage());
             return $form->response(Form::STATUS_ERROR);
         }
     }
 }
开发者ID:elvyrra,项目名称:hawk,代码行数:27,代码来源:LanguageController.php


注:本文中的Lang::exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。