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


PHP StringUtil::generateAlias方法代碼示例

本文整理匯總了PHP中StringUtil::generateAlias方法的典型用法代碼示例。如果您正苦於以下問題:PHP StringUtil::generateAlias方法的具體用法?PHP StringUtil::generateAlias怎麽用?PHP StringUtil::generateAlias使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在StringUtil的用法示例。


在下文中一共展示了StringUtil::generateAlias方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: generateAlias

 /**
  * Auto-generate the FAQ alias if it has not been set yet
  *
  * @param mixed         $varValue
  * @param DataContainer $dc
  *
  * @return mixed
  *
  * @throws Exception
  */
 public function generateAlias($varValue, DataContainer $dc)
 {
     $autoAlias = false;
     // Generate alias if there is none
     if ($varValue == '') {
         $autoAlias = true;
         $varValue = StringUtil::generateAlias($dc->activeRecord->question);
     }
     $objAlias = $this->Database->prepare("SELECT id FROM tl_faq WHERE alias=?")->execute($varValue);
     // Check whether the news alias exists
     if ($objAlias->numRows > 1 && !$autoAlias) {
         throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue));
     }
     // Add ID to alias
     if ($objAlias->numRows && $autoAlias) {
         $varValue .= '-' . $dc->id;
     }
     return $varValue;
 }
開發者ID:contao,項目名稱:faq-bundle,代碼行數:29,代碼來源:tl_faq.php

示例2: generateAlias

 /**
  * Auto-generate a page alias if it has not been set yet
  *
  * @param mixed         $varValue
  * @param DataContainer $dc
  *
  * @return string
  *
  * @throws Exception
  */
 public function generateAlias($varValue, DataContainer $dc)
 {
     $autoAlias = false;
     // Generate an alias if there is none
     if ($varValue == '') {
         $autoAlias = true;
         $varValue = StringUtil::generateAlias($dc->activeRecord->title);
         // Generate folder URL aliases (see #4933)
         if (Config::get('folderUrl')) {
             $objPage = PageModel::findWithDetails($dc->activeRecord->id);
             if ($objPage->folderUrl != '') {
                 $varValue = $objPage->folderUrl . $varValue;
             }
         }
     }
     $objAlias = $this->Database->prepare("SELECT id FROM tl_page WHERE id=? OR alias=?")->execute($dc->id, $varValue);
     // Check whether the page alias exists
     if ($objAlias->numRows > ($autoAlias ? 0 : 1)) {
         $arrPages = array();
         $strDomain = '';
         $strLanguage = '';
         while ($objAlias->next()) {
             $objCurrentPage = PageModel::findWithDetails($objAlias->id);
             $domain = $objCurrentPage->domain ?: '*';
             $language = !$objCurrentPage->rootIsFallback ? $objCurrentPage->rootLanguage : '*';
             // Store the current page's data
             if ($objCurrentPage->id == $dc->id) {
                 // Get the DNS and language settings from the POST data (see #4610)
                 if ($objCurrentPage->type == 'root') {
                     $strDomain = Input::post('dns');
                     $strLanguage = Input::post('language');
                 } else {
                     $strDomain = $domain;
                     $strLanguage = $language;
                 }
             } else {
                 // Check the domain and language or the domain only
                 if (Config::get('addLanguageToUrl')) {
                     $arrPages[$domain][$language][] = $objAlias->id;
                 } else {
                     $arrPages[$domain][] = $objAlias->id;
                 }
             }
         }
         $arrCheck = Config::get('addLanguageToUrl') ? $arrPages[$strDomain][$strLanguage] : $arrPages[$strDomain];
         // Check if there are multiple results for the current domain
         if (!empty($arrCheck)) {
             if ($autoAlias) {
                 $varValue .= '-' . $dc->id;
             } else {
                 throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue));
             }
         }
     }
     return $varValue;
 }
開發者ID:Mozan,項目名稱:core-bundle,代碼行數:66,代碼來源:tl_page.php

示例3: addAliasButton

 /**
  * Automatically generate the folder URL aliases
  *
  * @param array $arrButtons
  *
  * @return array
  */
 public function addAliasButton($arrButtons)
 {
     // Generate the aliases
     if (Input::post('FORM_SUBMIT') == 'tl_select' && isset($_POST['alias'])) {
         /** @var Symfony\Component\HttpFoundation\Session\SessionInterface $objSession */
         $objSession = System::getContainer()->get('session');
         $session = $objSession->all();
         $ids = $session['CURRENT']['IDS'];
         foreach ($ids as $id) {
             $objArticle = ArticleModel::findByPk($id);
             if ($objArticle === null) {
                 continue;
             }
             // Set the new alias
             $strAlias = StringUtil::generateAlias($objArticle->title);
             // The alias has not changed
             if ($strAlias == $objArticle->alias) {
                 continue;
             }
             // Initialize the version manager
             $objVersions = new Versions('tl_article', $id);
             $objVersions->initialize();
             // Store the new alias
             $this->Database->prepare("UPDATE tl_article SET alias=? WHERE id=?")->execute($strAlias, $id);
             // Create a new version
             $objVersions->create();
         }
         $this->redirect($this->getReferer());
     }
     // Add the button
     $arrButtons['alias'] = '<button type="submit" name="alias" id="alias" class="tl_submit" accesskey="a">' . $GLOBALS['TL_LANG']['MSC']['aliasSelected'] . '</button> ';
     return $arrButtons;
 }
開發者ID:Mozan,項目名稱:core-bundle,代碼行數:40,代碼來源:tl_article.php

示例4: generateAlias

 /**
  * @param $varValue
  * @param DataContainer $dc
  * @return string
  * @throws Exception
  */
 public function generateAlias($varValue, \DataContainer $dc)
 {
     // Generate an alias if there is none
     if ($varValue == '') {
         $varValue = StringUtil::generateAlias($dc->activeRecord->name);
     }
     $objAlias = $this->Database->prepare("SELECT id FROM tl_taxonomies WHERE (id=? OR alias=?) AND pid = ?")->execute($dc->id, $varValue, $dc->activeRecord->pid);
     // Check whether the Taxonomy alias exists
     if ($objAlias->numRows > 1) {
         $varValue .= '-' . $dc->id;
     }
     return $varValue;
 }
開發者ID:alnv,項目名稱:fmodul,代碼行數:19,代碼來源:tl_taxonomies.php

示例5: generateAlias

 /**
  * @param $varValue mixed The current alias (if available)
  * @param $intId    int The entity's id
  * @param $strTable string The entity's table
  * @param $strAlias string The value to use as a base for the alias
  *
  * @return string
  * @throws \Exception
  */
 public static function generateAlias($varValue, $intId, $strTable, $strAlias)
 {
     $autoAlias = false;
     // Generate alias if there is none
     if ($varValue == '') {
         $autoAlias = true;
         $varValue = \StringUtil::generateAlias($strAlias);
     }
     $objAlias = \Database::getInstance()->prepare("SELECT id FROM {$strTable} WHERE alias=?")->execute($varValue);
     // Check whether the alias exists
     if ($objAlias->numRows > 1 && !$autoAlias) {
         throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue));
     }
     // Add ID to alias
     if ($objAlias->numRows && $objAlias->id != $intId && $autoAlias || !$varValue) {
         $varValue .= '-' . $intId;
     }
     return $varValue;
 }
開發者ID:heimrichhannot,項目名稱:contao-haste_plus,代碼行數:28,代碼來源:General.php

示例6: generateAlias

 /**
  * @param $varValue
  * @param array $arrData
  * @return string
  * @throws \Exception
  */
 protected function generateAlias($varValue, $arrData = array())
 {
     $autoAlias = false;
     if (!$arrData['title'] || empty($arrData)) {
         return 'Alias-' . substr(md5(time()), 12);
     }
     // Generate alias if there is none
     if ($varValue == '') {
         $autoAlias = true;
         $varValue = \StringUtil::generateAlias($arrData['title']);
     }
     $table = $this->strTableData;
     $pid = $this->strPid;
     $objAlias = null;
     if ($table && $pid) {
         $objAlias = $this->Database->prepare("SELECT id FROM " . $table . " WHERE alias = ? AND pid = ?")->execute($varValue, $pid);
     }
     // Check whether the alias exists
     if ($objAlias && $objAlias->numRows > 1 && !$autoAlias) {
         throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue));
     }
     // Add hash to alias
     if ($objAlias && $objAlias->numRows && $autoAlias) {
         $varValue .= '-' . substr(md5(time()), 12);
     }
     return $varValue;
 }
開發者ID:alnv,項目名稱:fmodul,代碼行數:33,代碼來源:ModuleFModuleRegistration.php

示例7: generateAlias

 public function generateAlias($strString)
 {
     return \StringUtil::generateAlias($strString);
 }
開發者ID:thunder1902,項目名稱:examples,代碼行數:4,代碼來源:StringUtilService.php

示例8: addAliasButton

 /**
  * @param $arrButtons
  * @return string
  */
 public function addAliasButton($arrButtons)
 {
     if (\Input::post('FORM_SUBMIT') == 'tl_select' && isset($_POST['alias'])) {
         // init objects
         $objSession = \Session::getInstance();
         $objDataBase = \Database::getInstance();
         $session = $objSession->getData();
         $ids = $session['CURRENT']['IDS'];
         $strTable = \Input::get('table');
         if (!$strTable || !$objDataBase->tableExists($strTable)) {
             return $arrButtons;
         }
         foreach ($ids as $id) {
             $objData = $objDataBase->prepare('SELECT id, alias, title FROM ' . $strTable . ' WHERE id=?')->limit(1)->execute($id);
             if (!$objData->count()) {
                 continue;
             }
             $arrData = $objData->row();
             $strAlias = \StringUtil::generateAlias($arrData['title']);
             if ($strAlias == $arrData['alias']) {
                 continue;
             }
             $objAlias = $objDataBase->prepare('SELECT id FROM ' . $strTable . ' WHERE alias = ?')->execute($strAlias);
             if ($objAlias->numRows > 1) {
                 $strAlias .= '-' . $arrData['id'];
             }
             // Initialize the version manager
             $objVersions = new \Versions($strTable, $id);
             $objVersions->initialize();
             $objDataBase->prepare('UPDATE ' . $strTable . ' SET alias=? WHERE id=?')->execute($strAlias, $id);
             $objVersions->create();
         }
         \Controller::redirect(\Controller::getReferer());
     }
     $arrButtons['alias'] = '<input type="submit" name="alias" id="alias" class="tl_submit" accesskey="a" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['aliasSelected']) . '"> ';
     return $arrButtons;
 }
開發者ID:alnv,項目名稱:fmodul,代碼行數:41,代碼來源:DCACreator.php


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