本文整理汇总了PHP中PageModel::findById方法的典型用法代码示例。如果您正苦于以下问题:PHP PageModel::findById方法的具体用法?PHP PageModel::findById怎么用?PHP PageModel::findById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PageModel
的用法示例。
在下文中一共展示了PageModel::findById方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkForShortURL
public function checkForShortURL()
{
// only do something in the frontend
if (TL_MODE != 'FE') {
return;
}
// check if we have one or more Short URLs
if (($objShortURL = \ShortURLsModel::findActiveByName(\Environment::get('request'))) !== null) {
// go through each short URL
while ($objShortURL->next()) {
// check if there is a target set
if (!$objShortURL->target) {
continue;
}
// check for domain restriction
if ($objShortURL->domain) {
if (($objDomain = \PageModel::findById($objShortURL->domain)) !== null) {
if (strcasecmp($objDomain->dns, \Environment::get('host')) !== 0) {
continue;
}
}
}
// build redirect URL
$url = self::processTarget($objShortURL->target);
// prevent infinite redirects
if ($url == \Environment::get('base') . \Environment::get('request')) {
continue;
}
// execute redirect
\Controller::redirect($url, $objShortURL->redirect == 'permanent' ? 301 : 302);
}
}
}
示例2: checkLog
public function checkLog($ptable, $tstamp, $item)
{
switch ($ptable) {
case 'tl_article':
$objArticle = \ArticleModel::findById($item['pid']);
$objPage = \PageModel::findById($objArticle->pid);
$item['page'] = $objPage->title;
$item['showUrl'] = $this->generateFrontendUrl($objPage->row(), '');
break;
case 'tl_news':
$objNews = \NewsModel::findById($item['pid']);
$objArchive = \NewsArchiveModel::findById($objNews->pid);
$objPage = \PageModel::findById($objArchive->jumpTo);
$item['page'] = $objNews->headline;
$item['showUrl'] = ampersand($this->generateFrontendUrl($objPage->row(), (\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/' : '/items/') . (!\Config::get('disableAlias') && $objNews->alias != '' ? $objNews->alias : $objNews->id)));
break;
case 'tl_calendar':
break;
case 'tl_faq':
$objFAQ = \FaqModel::findById($item['id']);
$objCategory = \FaqCategoryModel::findById($item['pid']);
$objPage = \PageModel::findById($objCategory->jumpTo);
$item['htmlElement'] = '<div class="ce_faq"><h1>' . $objFAQ->question . '</h1>' . $objFAQ->answer . '</div>';
$item['page'] = $objCategory->title;
$item['title'] = $objFAQ->question;
$item['showUrl'] = ampersand($this->generateFrontendUrl($objPage->row(), (\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/' : '/items/') . (!\Config::get('disableAlias') && $objFAQ->alias != '' ? $objFAQ->alias : $objFAQ->id)));
break;
}
return $item;
}
示例3: compile
/**
* Generate the content element
*/
protected function compile()
{
$arrItems = array();
$t = 'tl_calendar_events';
if ($this->include_type == 'archives') {
$arrArchiveIds = deserialize($this->include_archives, true);
$strSortOrder = $this->sortOrder == 'ascending' ? 'ASC' : 'DESC';
if (sizeof($arrArchiveIds)) {
$arrColumns = array("{$t}.pid IN(" . implode(',', array_map('intval', $arrArchiveIds)) . ")");
if (!BE_USER_LOGGED_IN) {
$time = time();
$arrColumns[] = "({$t}.start='' OR {$t}.start<{$time}) AND ({$t}.stop='' OR {$t}.stop>{$time}) AND {$t}.published=1";
}
$objItems = \CalendarEventsModel::findBy($arrColumns, null, array('order' => 'startDate ' . $strSortOrder));
}
} else {
$arrItemIds = deserialize($this->include_items, true);
if (sizeof($arrItemIds)) {
$arrItems = array_map(function () {
return '';
}, array_flip($arrItemIds));
$arrColumns = array("{$t}.id IN(" . implode(',', array_map('intval', $arrItemIds)) . ")");
if (!BE_USER_LOGGED_IN) {
$time = time();
$arrColumns[] = "({$t}.start='' OR {$t}.start<{$time}) AND ({$t}.stop='' OR {$t}.stop>{$time}) AND {$t}.published=1";
}
$objItems = \CalendarEventsModel::findBy($arrColumns, null);
}
}
if (!is_null($objItems)) {
while ($objItems->next()) {
$objReaderPage = \PageModel::findById($objItems->getRelated('pid')->jumpTo);
$arrItem = $objItems->row();
$arrItem['dateStart'] = \Date::parse('Y-m-d', $objItems->startDate);
$arrItem['dateStartReadable'] = \Date::parse(\Config::get('dateFormat') ?: 'Y-m-d', $objItems->startDate);
if ($objItems->endDate) {
$arrItem['dateEnd'] = \Date::parse('Y-m-d', $objItems->endDate);
$arrItem['dateEndReadable'] = \Date::parse(\Config::get('dateFormat') ?: 'Y-m-d', $objItems->endDate);
}
$arrItem['href'] = ampersand($this->generateFrontendUrl($objReaderPage->row(), (\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/' : '/items/') . (!\Config::get('disableAlias') && $objItems->alias != '' ? $objItems->alias : $objItems->id)));
$arrItems[$objItems->id] = $arrItem;
}
}
$this->Template->items = array_filter($arrItems);
}
示例4: getColor
public static function getColor($masterColor = null)
{
$page = $GLOBALS['objPage'];
if ($page->color) {
return $page->color;
}
if (!$page->rootId) {
return null;
}
$rootPage = \PageModel::findById($page->rootId);
if ($rootPage->base_color) {
return $rootPage->base_color;
}
if ($masterColor) {
return $masterColor;
}
return null;
}
示例5: compile
protected function compile()
{
if ($this->check_news && FE_USER_LOGGED_IN) {
$this->Import('FrontendUser', 'Member');
$objMember = \MemberModel::findById($this->Member->id);
$arrArchives = deserialize($this->news_archives);
if (is_array($arrArchives)) {
$objNews = $this->Database->prepare("SELECT * FROM tl_news WHERE pid IN(" . implode(",", $arrArchives) . ") && tstamp > ? && published='1'")->execute($objMember->lastLogin);
if (!$objNews->count()) {
$objPage = \PageModel::findById($this->jumpTo);
\Controller::redirect(\Controller::generateFrontendUrl($objPage->row(), ''));
}
}
}
if (!FE_USER_LOGGED_IN && $this->redirecter_guests or FE_USER_LOGGED_IN && $this->redirecter_protected) {
$objPage = \PageModel::findById($this->jumpTo);
$this->redirect($this->generateFrontendUrl($objPage->row(), ''));
}
}
示例6: replaceScrollTag
public function replaceScrollTag($strTag)
{
$value = false;
$arrExplode = explode("::", $strTag);
if ($arrExplode[0] == "scroll" && count($arrExplode) == 3) {
if (substr($arrExplode[1], 0, 1) == "#") {
$arrExplode[1] = substr($arrExplode[1], 1);
}
$value = '<a href="#" data-scroll="' . $arrExplode[1] . '" title="' . $arrExplode[2] . '">' . $arrExplode[2] . '</a>';
}
if ($arrExplode[0] == "lightbox") {
$objPage = \PageModel::findById($arrExplode[1]);
$url = $this->generateFrontendUrl($objPage->row(), '');
if ($objPage->pageTitle) {
$objPage->title = $objPage->pageTitle;
}
$value = '<a href="' . $url . '" class="cboxElement" title="' . $objPage->title . '">' . $objPage->title . '</a>';
}
return $value;
}
示例7: checkAlias
/**
* Check the news alias for duplicates
*
* @param mixed $varValue
* @param DataContainer $dc
*
* @return string
*
* @throws Exception
*/
public function checkAlias($varValue, DataContainer $dc)
{
// get the news archive first
if (($objArchive = \NewsArchiveModel::findById($dc->activeRecord->pid)) !== null) {
// get the redirect page
if (($objTarget = \PageModel::findById($objArchive->jumpTo)) !== null) {
// check if there is a page with the same alias
if (($objPage = \PageModel::findByAlias($varValue)) !== null) {
// load the details
$objTarget->current()->loadDetails();
$objPage->current()->loadDetails();
// check if page is on the same domain and language
if ($objPage->domain == $objTarget->domain && (\Config::get('addLanguageToUrl') && $objPage->rootLanguage == $objTarget->rootLanguage)) {
// append id
$varValue .= '-' . $dc->id;
}
}
}
}
// return the alias
return $varValue;
}
示例8: labelCallback
/**
* Display list info in the backend
*
* @param array $arrRow
*
* @return string
*/
public function labelCallback($arrRow)
{
// get the target URL
$targetURL = \ShortURLs::processTarget($arrRow['target']);
// remove current host
$targetURL = str_replace(\Environment::get('base'), '', $targetURL);
// check for domain restriction
$domain = '';
if ($arrRow['domain'] && ($objPage = \PageModel::findById($arrRow['domain'])) !== null) {
$domain = $objPage->dns . '/';
}
// generate list record
return '<div class="tl_content_right"><span style="color:rgb(200,200,200)">[' . ($arrRow['redirect'] == 'permanent' ? 301 : 302) . ']</span></div><div class="tl_content_left">' . $domain . $arrRow['name'] . ' » ' . $targetURL . ' </div>';
}
示例9: setDataFor
/**
* This method is called to store the data for certain items to the database.
*
* @param mixed $arrValues The values to be stored into database. Mapping is item id=>value.
*
* @return void
*/
public function setDataFor($arrValues)
{
$strTable = $this->getMetaModel()->getTableName();
$strColName = $this->getColName();
//get the page model to get the current title and alias to set it to the category
//
// $model->setProperty('name',$pageModel->title);
// $model->setProperty('alias',$pageModel->alias);
// $model->getItem()->save();
//var_dump($strColName,$arrValues);
foreach ($arrValues as $intId => $varData) {
if (is_array($varData)) {
$varData = serialize($varData);
}
$pageModel = \PageModel::findById($varData);
$AttributeIsTranslatedData = function ($attribute) {
return in_array('setTranslatedDataFor', get_class_methods($this->getMetaModel()->getAttribute($attribute)));
};
// var_dump( $this->getMetaModel()->getAttribute('name'));
if ($AttributeIsTranslatedData('name') || $AttributeIsTranslatedData('alias')) {
echo 'You use translated attributes for name or alias. You have to use the attribute type of "attribute_translatedpageid"';
exit;
} elseif (Null === $this->getMetaModel()->getAttribute('name') || Null === $this->getMetaModel()->getAttribute('alias')) {
echo 'You need the fields "name" and "alias" in your table:' . $strTable;
exit;
} else {
$this->getMetaModel()->getServiceContainer()->getDatabase()->prepare(sprintf('UPDATE %s
SET %s=? , %s=? ,%s=?
WHERE id=%s', $strTable, $strColName, 'name', 'alias', $intId))->execute($varData, $pageModel->title, $pageModel->alias);
}
}
}
示例10: fixDomain
public function fixDomain($objTemplate, $arrArticle, $objModule)
{
// set base class
$objTemplate->class .= ' source-' . $arrArticle['source'];
// check for internal source
if ($arrArticle['source'] != 'internal' && $arrArticle['source'] != 'default') {
return;
}
// get current page object
global $objPage;
// prepare new href
$strHref = '';
// case for internal source
if ($arrArticle['source'] == 'internal') {
// check for target page
if (($objTarget = \PageModel::findById($arrArticle['jumpTo'])) === null) {
return;
}
// load the page details
$objTarget->current()->loadDetails();
// check for domain and language
if ($objTarget->domain != '' && $objTarget->domain != \Environment::get('host')) {
$objTemplate->class .= '-domain';
} elseif (\Config::get('addLanguageToUrl') && $objTarget->rootLanguage != $objPage->rootLanguage) {
$objTemplate->class .= '-lang';
} else {
return;
}
// build the href
$strHref = '';
if (version_compare(VERSION, '3.3', '<')) {
$strHref = $this->generateFrontendUrl($objTarget->row(), null, $objTarget->rootLanguage);
$strHref = ($objTarget->rootUseSSL ? 'https://' : 'http://') . $objTarget->domain . TL_PATH . '/' . $strHref;
} else {
$strHref = $this->generateFrontendUrl($objTarget->row(), null, $objTarget->rootLanguage, true);
}
} elseif ($arrArticle['source'] == 'default') {
// determine the target
$objTarget = null;
// check if module has a target set
if ($objModule->jumpTo) {
$objTarget = \PageModel::findByPk($objModule->jumpTo);
}
if ($objTarget === null && ($objArchive = \NewsArchiveModel::findByPk($arrArticle['pid'])) !== null) {
$objTarget = \PageModel::findByPk($objArchive->jumpTo);
}
// check for target page
if ($objTarget === null) {
return;
}
// load the page details
$objTarget->current()->loadDetails();
// check for domain and language
if ($objTarget->domain != '' && $objTarget->domain != \Environment::get('host')) {
$objTemplate->class .= '-domain';
} elseif (\Config::get('addLanguageToUrl') && $objTarget->rootLanguage != $objPage->rootLanguage) {
$objTemplate->class .= '-lang';
} elseif (!$objModule->jumpTo) {
return;
}
// build the href
if (version_compare(VERSION, '3.3', '<')) {
$strHref = $this->generateFrontendUrl($objTarget->row(), (\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/' : '/items/') . (!\Config::get('disableAlias') && $arrArticle['alias'] != '' ? $arrArticle['alias'] : $arrArticle['id']), $objTarget->rootLanguage);
$strHref = ($objTarget->rootUseSSL ? 'https://' : 'http://') . $objTarget->domain . TL_PATH . '/' . $strHref;
} else {
$strHref = $this->generateFrontendUrl($objTarget->row(), (\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/' : '/items/') . (!\Config::get('disableAlias') && $arrArticle['alias'] != '' ? $arrArticle['alias'] : $arrArticle['id']), $objTarget->rootLanguage, true);
}
}
// encode href
$strHref = ampersand($strHref);
// update links
$objTemplate->link = $strHref;
$objTemplate->linkHeadline = $this->generateInternalLink($strHref, $arrArticle['headline'], $arrArticle['headline']);
$objTemplate->more = $this->generateInternalLink($strHref, $arrArticle['headline'], $GLOBALS['TL_LANG']['MSC']['more'], true);
}
示例11: setTranslatedDataFor
/**
* {@inheritdoc}
*/
public function setTranslatedDataFor($values, $language)
{
$values = (array) $values;
if (!$values) {
return;
}
$this->unsetValueFor(array_keys($values), $language);
$DB = $this->getMetaModel()->getServiceContainer()->getDatabase();
$sql = sprintf('INSERT INTO %1$s (att_id, item_id, langcode, tstamp, value_id) VALUES %2$s', $this->getValueTable(), rtrim(str_repeat('(?,?,?,?,?),', count($values)), ','));
$time = time();
$params = array();
foreach ($values as $id => $value) {
$params[] = $this->get('id');
$params[] = $id;
$params[] = $language;
$params[] = $time;
$params[] = $value['value'];
}
$DB->prepare($sql)->execute($params);
//set name and alias
$AttributeIsTranslatedData = function ($attribute) {
return in_array('setTranslatedDataFor', get_class_methods($this->getMetaModel()->getAttribute($attribute)));
};
if (!$AttributeIsTranslatedData('name') || !$AttributeIsTranslatedData('alias')) {
echo 'You have to use translated attributes for name or alias if you use the attribute type of "attribute_translatedpageid"';
exit;
} elseif (Null === $this->getMetaModel()->getAttribute('name') || Null === $this->getMetaModel()->getAttribute('alias')) {
echo 'You need the translated text attributes "name" and "alias" in your MetaModel:' . $strTable;
exit;
} else {
// Nur type Text für Name und Alias verwenden. Alias funktioniert (noch) nicht.
$pageModel = \PageModel::findById($value['value']);
$translatedTextValueTable = 'tl_metamodel_translatedtext';
$currentId = array_keys($values)[0];
//$this->get('id');
$nameAttrId = $this->getMetaModel()->getAttribute('name')->get('id');
$aliasAttrId = $this->getMetaModel()->getAttribute('alias')->get('id');
//to unset it find with item_id & attr_id & langcode -> es darf nur eins geben!
//set new Items
/*
`id` int(10) unsigned NOT NULL auto_increment,
`tstamp` int(10) unsigned NOT NULL default '0',
`att_id` int(10) unsigned NOT NULL default '0',
`item_id` int(10) unsigned NOT NULL default '0',
`langcode` varchar(5) NOT NULL default '',
`value` varchar(255) NOT NULL default '',
*/
// Name
$sqlSETName = "INSERT INTO " . $translatedTextValueTable . " (att_id, item_id, langcode, tstamp, value) VALUES (?,?,?,?,?) ";
$DB->prepare($sqlSETName)->execute($nameAttrId, $currentId, $language, $time, $pageModel->title);
// Alias
$sqlSETAlias = "INSERT INTO " . $translatedTextValueTable . " (att_id, item_id, langcode, tstamp, value) VALUES (?,?,?,?,?) ";
$DB->prepare($sqlSETAlias)->execute($aliasAttrId, $currentId, $language, $time, $pageModel->alias);
}
}