本文整理汇总了PHP中ArticleModel::findByPk方法的典型用法代码示例。如果您正苦于以下问题:PHP ArticleModel::findByPk方法的具体用法?PHP ArticleModel::findByPk怎么用?PHP ArticleModel::findByPk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArticleModel
的用法示例。
在下文中一共展示了ArticleModel::findByPk方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* Parse the template
* @return string
*/
public function generate()
{
if (TL_MODE == 'BE') {
// create new backend template
$objTemplate = new \BackendTemplate('be_include');
// get the article
$objArticle = \ArticleModel::findByPk($this->articleAlias);
if ($objArticle === null) {
return parent::generate();
}
// get the parent pages
$objPages = \PageModel::findParentsById($objArticle->pid);
if ($objPages === null) {
return parent::generate();
}
// get the page titles
$arrPageTitles = array_reverse($objPages->fetchEach('title'));
// set breadcrumb to original element
$objTemplate->original = array('crumbs' => implode(' » ', $arrPageTitles), 'article' => array('title' => $objArticle->title, 'link' => 'contao/main.php?do=article&table=tl_content&id=' . $objArticle->id . '&rt=' . REQUEST_TOKEN));
// get include breadcrumbs
$includes = \IncludeInfoHelper::getIncludes('articleAlias', $this->articleAlias, $this->id);
// set include breadcrumbs
if (count($includes) > 1) {
$objTemplate->includes = $includes;
}
// add CSS
$GLOBALS['TL_CSS'][] = \IncludeInfoHelper::BACKEND_CSS;
// return info + content
return $objTemplate->parse() . parent::generate();
}
// return content only
return parent::generate();
}
示例2: compile
protected function compile()
{
$objContentStart = \Database::getInstance()->prepare("SELECT * FROM tl_content WHERE pid=? AND type=? ORDER BY sorting")->limit(1)->execute($this->pid, 'formhybridStart');
if ($objContentStart->numRows === 0) {
return;
}
$objModule = \ModuleModel::findByPk($objContentStart->formhybridModule);
if ($objModule === null) {
return;
}
$objModule->refresh();
$strClass = \Module::findClass($objModule->type);
// Return if the class does not exist
if (!class_exists($strClass)) {
static::log('Module class "' . $strClass . '" (module "' . $objModule->type . '") does not exist', __METHOD__, TL_ERROR);
return '';
}
$objArticle = \ArticleModel::findByPk($this->pid);
if ($objArticle === null) {
return;
}
global $objPage;
$objModule = new $strClass($objModule, $objArticle->inColumn);
$objModule->renderStop = true;
$objModule->startModule = $_SESSION[FormSession::FORMHYBRID_FORMSESSION_START_KEY][$objPage->id . '_' . $objModule->formHybridDataContainer];
$this->Template->content = $objModule->generate();
}
示例3: EditAction
protected function EditAction($id)
{
try {
$editArt = ArticleModel::findByPk($id);
} catch (Exception $e) {
echo "Исключение: " . $e->getMessage();
die;
}
$editArt->title = $_POST['title'];
$editArt->content = $_POST['content'];
$editArt->id = $_POST['id'];
$editArt->save();
$view = new View();
$view->display('change.php');
}
示例4: loadArticleDca
public function loadArticleDca($dc)
{
$layout = null;
$article = \ArticleModel::findByPk($dc->id);
$page = \PageModel::findWithDetails($article->pid);
while (!$layout && $page) {
if ($page->includeLayout) {
$layout = \LayoutModel::findByPk($page->layout);
} else {
$page = \PageModel::findWithDetails($page->pid);
}
}
if ($layout && $layout->useRevealJs) {
\MetaPalettes::appendFields('tl_article', 'default', 'template', array('revealVerticalSlide'));
}
}
示例5: getPageBootstrapArticles
/**
* get all articles in bootstrap section of an article
*
* @param $mcw
* @return array
*/
public function getPageBootstrapArticles($mcw)
{
if ($this->articles === null) {
$article = \ArticleModel::findByPk($mcw->activeRecord->pid);
$model = \ArticleModel::findAll(array('column' => 'pid =? AND inColumn', 'value' => array($article->pid, 'bootstrap')));
$articles = array();
if ($model === null) {
return $articles;
}
while ($model->next()) {
$articles[$model->id] = $model->title;
}
$this->articles = $articles;
}
return $this->articles;
}
示例6: createItem
public function createItem(CreateItemEvent $event)
{
$item = $event->getItem();
if ($item->getType() == 'article') {
$article = \ArticleModel::findByPk($item->getName());
if ($article) {
$page = \PageModel::findByPk($article->pid);
if ($page) {
$cssID = deserialize($article->cssID, true);
$item->setUri(\Frontend::generateFrontendUrl($page->row()) . '#' . (empty($cssID[0]) ? $article->alias : $cssID[0]));
$item->setLabel($article->title);
$item->setExtras($article->row());
}
}
}
}
示例7: getContentSliderCarousels
public function getContentSliderCarousels(DataContainer $dc)
{
$arrOptions = array();
$objSlider = \ContentModel::findBy('type', 'slick-content-start');
if ($objSlider === null) {
return $arrOptions;
}
while ($objSlider->next()) {
$objArticle = \ArticleModel::findByPk($objSlider->pid);
if ($objArticle === null) {
continue;
}
$arrOptions[$objSlider->id] = sprintf($GLOBALS['TL_LANG']['tl_content']['contentSliderCarouselSelectOption'], $objArticle->title, $objArticle->id, $objSlider->id);
}
return $arrOptions;
}
示例8: generate
/**
* Parse the template
* @return string
*/
public function generate()
{
if (TL_MODE == 'BE') {
// create new backend template
$objTemplate = new \BackendTemplate('be_include');
// get all include elements
$objElements = \ContentModel::findBy('module', $this->module, array('order' => 'id'));
// prepare include breadcrumbs
$includes = array();
// go throuch each include element
while ($objElements->next()) {
// get the parent article
$objArticle = \ArticleModel::findByPk($objElements->pid);
if ($objArticle === null) {
continue;
}
// get the parent pages
$objPages = \PageModel::findParentsById($objArticle->pid);
if ($objPages === null) {
continue;
}
// get the page titles
$arrPageTitles = array_reverse($objPages->fetchEach('title'));
// css classes for list
$classes = array();
if ($objElements->id == $this->id) {
$classes[] = 'self';
}
if ($objElements->invisible) {
$classes[] = 'hidden';
}
// create breadcrumb
$includes[] = array('crumbs' => implode(' » ', $arrPageTitles), 'article' => array('title' => $objArticle->title, 'link' => 'contao/main.php?do=article&table=tl_content&id=' . $objArticle->id . '&rt=' . REQUEST_TOKEN), 'class' => implode(' ', $classes));
}
// set include breadcrumbs
if (count($includes) > 1) {
$objTemplate->includes = $includes;
}
// add CSS
$GLOBALS['TL_CSS'][] = \IncludeInfoHelper::BACKEND_CSS;
// return info + content
return $objTemplate->parse() . parent::generate();
}
// return content only
return parent::generate();
}
示例9: addParentToBreadcrumb
/**
* Add the parent to the breadcrumb.
*
* @param ContentModel $model The content model.
* @param Breadcrumb $breadcrumb The breadcrumb.
*
* @return void
*/
private function addParentToBreadcrumb(ContentModel $model, Breadcrumb $breadcrumb)
{
if ($model) {
switch ($model->ptable) {
case 'tl_article':
case '':
$article = \ArticleModel::findByPk($model->pid);
$breadcrumb->addNode($article->id, $article->title, 'article', false);
break;
// TODO: News and Events
// TODO: Event for others.
// TODO: News and Events
// TODO: Event for others.
default:
// Do Nothing.
}
}
}
示例10: getIncludes
public static function getIncludes($where, $includeId, $selfId = null)
{
// get all include elements
$objElements = \ContentModel::findBy($where, $includeId, array('order' => 'id'));
// check for result
if ($objElements === null) {
return array();
}
// prepare include breadcrumbs
$includes = array();
// go throuch each include element
while ($objElements->next()) {
// get the parent article
$objArticle = \ArticleModel::findByPk($objElements->pid);
if ($objArticle === null) {
continue;
}
// get the parent pages
$objPages = \PageModel::findParentsById($objArticle->pid);
if ($objPages === null) {
continue;
}
// get the page titles
$arrPageTitles = array_reverse($objPages->fetchEach('title'));
// css classes for list
$classes = array();
if ($objElements->id == $selfId) {
$classes[] = 'self';
}
if ($objElements->invisible) {
$classes[] = 'hidden';
}
// create breadcrumb
$includes[] = array('crumbs' => implode(' » ', $arrPageTitles), 'article' => array('title' => $objArticle->title, 'link' => 'contao/main.php?do=article&table=tl_content&id=' . $objArticle->id . '&rt=' . REQUEST_TOKEN), 'class' => implode(' ', $classes));
}
// return the include elements
return $includes;
}
示例11: replaceInsertTags
//.........这里部分代码省略.........
break;
} else {
$strUrl = $this->generateFrontendUrl($objFaq->row(), ($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/' : '/items/') . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objFaq->alias != '' ? $objFaq->alias : $objFaq->id));
}
// Replace the tag
switch (strtolower($elements[0])) {
case 'faq':
$strLink = specialchars($objFaq->question);
$arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, $strLink, $strLink);
break;
case 'faq_open':
$arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objFaq->question));
break;
case 'faq_url':
$arrCache[$strTag] = $strUrl;
break;
case 'faq_title':
$arrCache[$strTag] = specialchars($objFaq->question);
break;
}
break;
// News
// News
case 'news':
case 'news_open':
case 'news_url':
case 'news_title':
$objNews = \NewsModel::findByIdOrAlias($elements[1]);
if ($objNews === null) {
break;
} elseif ($objNews->source == 'internal') {
$strUrl = $this->generateFrontendUrl($objNews->getRelated('jumpTo')->row());
} elseif ($objNews->source == 'article') {
$objArticle = \ArticleModel::findByPk($objNews->articleId, array('eager' => true));
$strUrl = $this->generateFrontendUrl($objArticle->pid, '/articles/' . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id));
} elseif ($objNews->source == 'external') {
$strUrl = $objNews->url;
} else {
$strUrl = $this->generateFrontendUrl($objNews->pid, ($GLOBALS['TL_CONFIG']['useAutoItem'] ? '/' : '/items/') . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objNews->alias != '' ? $objNews->alias : $objNews->id));
}
// Replace the tag
switch (strtolower($elements[0])) {
case 'news':
$strLink = specialchars($objNews->headline);
$arrCache[$strTag] = sprintf('<a href="%s" title="%s">%s</a>', $strUrl, $strLink, $strLink);
break;
case 'news_open':
$arrCache[$strTag] = sprintf('<a href="%s" title="%s">', $strUrl, specialchars($objNews->headline));
break;
case 'news_url':
$arrCache[$strTag] = $strUrl;
break;
case 'news_title':
$arrCache[$strTag] = specialchars($objNews->headline);
break;
}
break;
// Events
// Events
case 'event':
case 'event_open':
case 'event_url':
case 'event_title':
$objEvent = \CalendarEventsModel::findByIdOrAlias($elements[1]);
if ($objEvent === null) {
break;
示例12: addEvent
/**
* Add an event to the array of active events
*
* @param \CalendarEventsModel $objEvent
* @param integer $intStart
* @param integer $intEnd
* @param string $strUrl
* @param string $strBase
*/
protected function addEvent($objEvent, $intStart, $intEnd, $strUrl, $strBase)
{
if ($intEnd < time()) {
return;
}
/** @var \PageModel $objPage */
global $objPage;
// Called in the back end (see #4026)
if ($objPage === null) {
$objPage = new \stdClass();
$objPage->dateFormat = \Config::get('dateFormat');
$objPage->datimFormat = \Config::get('datimFormat');
$objPage->timeFormat = \Config::get('timeFormat');
}
$intKey = date('Ymd', $intStart);
$span = self::calculateSpan($intStart, $intEnd);
$format = $objEvent->addTime ? 'datimFormat' : 'dateFormat';
// Add date
if ($span > 0) {
$title = \Date::parse($objPage->{$format}, $intStart) . ' – ' . \Date::parse($objPage->{$format}, $intEnd);
} else {
$title = \Date::parse($objPage->dateFormat, $intStart) . ($objEvent->addTime ? ' (' . \Date::parse($objPage->timeFormat, $intStart) . ($intStart < $intEnd ? ' – ' . \Date::parse($objPage->timeFormat, $intEnd) : '') . ')' : '');
}
// Add title and link
$title .= ' ' . $objEvent->title;
$link = '';
switch ($objEvent->source) {
case 'external':
$link = $objEvent->url;
break;
case 'internal':
if (($objTarget = $objEvent->getRelated('jumpTo')) !== null) {
$link = $strBase . $this->generateFrontendUrl($objTarget->row());
}
break;
case 'article':
if (($objArticle = \ArticleModel::findByPk($objEvent->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
$link = $strBase . ampersand($this->generateFrontendUrl($objPid->row(), '/articles/' . (!\Config::get('disableAlias') && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id)));
}
break;
}
// Link to the default page
if ($link == '') {
$link = $strBase . sprintf($strUrl, $objEvent->alias != '' && !\Config::get('disableAlias') ? $objEvent->alias : $objEvent->id);
}
// Store the whole row (see #5085)
$arrEvent = $objEvent->row();
// Override link and title
$arrEvent['link'] = $link;
$arrEvent['title'] = $title;
// Clean the RTE output
if ($objPage->outputFormat == 'xhtml') {
$arrEvent['teaser'] = \StringUtil::toXhtml($objEvent->teaser);
} else {
$arrEvent['teaser'] = \StringUtil::toHtml5($objEvent->teaser);
}
// Reset the enclosures (see #5685)
$arrEvent['enclosure'] = array();
// Add the article image as enclosure
if ($objEvent->addImage) {
$objFile = \FilesModel::findByUuid($objEvent->singleSRC);
if ($objFile !== null) {
$arrEvent['enclosure'][] = $objFile->path;
}
}
// Enclosures
if ($objEvent->addEnclosure) {
$arrEnclosure = deserialize($objEvent->enclosure, true);
if (is_array($arrEnclosure)) {
$objFile = \FilesModel::findMultipleByUuids($arrEnclosure);
if ($objFile !== null) {
while ($objFile->next()) {
$arrEvent['enclosure'][] = $objFile->path;
}
}
}
}
$this->arrEvents[$intKey][$intStart][] = $arrEvent;
}
示例13: generateEventUrl
/**
* Generate a URL and return it as string
*
* @param CalendarEventsModel $objEvent
*
* @return string
*/
public static function generateEventUrl($objEvent)
{
$strCacheKey = 'id_' . $objEvent->id;
// Load the URL from cache
if (isset(self::$arrUrlCache[$strCacheKey])) {
return self::$arrUrlCache[$strCacheKey];
}
// Initialize the cache
self::$arrUrlCache[$strCacheKey] = null;
switch ($objEvent->source) {
// Link to an external page
case 'external':
if (substr($objEvent->url, 0, 7) == 'mailto:') {
self::$arrUrlCache[$strCacheKey] = \StringUtil::encodeEmail($objEvent->url);
} else {
self::$arrUrlCache[$strCacheKey] = ampersand($objEvent->url);
}
break;
// Link to an internal page
// Link to an internal page
case 'internal':
if (($objTarget = $objEvent->getRelated('jumpTo')) !== null) {
self::$arrUrlCache[$strCacheKey] = ampersand(\Controller::generateFrontendUrl($objTarget->row()));
}
break;
// Link to an article
// Link to an article
case 'article':
if (($objArticle = \ArticleModel::findByPk($objEvent->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
self::$arrUrlCache[$strCacheKey] = ampersand(\Controller::generateFrontendUrl($objPid->row(), '/articles/' . ($objArticle->alias ?: $objArticle->id)));
}
break;
}
// Link to the default page
if (self::$arrUrlCache[$strCacheKey] === null) {
$objPage = \PageModel::findByPk($objEvent->getRelated('pid')->jumpTo);
if ($objPage === null) {
self::$arrUrlCache[$strCacheKey] = ampersand(\Environment::get('request'), true);
} else {
self::$arrUrlCache[$strCacheKey] = ampersand(\Controller::generateFrontendUrl($objPage->row(), (\Config::get('useAutoItem') ? '/' : '/events/') . ($objEvent->alias ?: $objEvent->id)));
}
}
return self::$arrUrlCache[$strCacheKey];
}
示例14: getLink
/**
* @param $objItem
* @param $strUrl
* @param string $strBase
* @return string
* @throws \Exception
*/
public static function getLink($objItem, $strUrl, $strBase = '')
{
// switch
switch ($objItem->source) {
// Link to an external page
case 'external':
return $objItem->url;
break;
// Link to an internal page
// Link to an internal page
case 'internal':
if ($objItem->jumpTo) {
$objPage = PageModel::findWithDetails($objItem->jumpTo);
$domain = ($objPage->rootUseSSL ? 'https://' : 'http://') . ($objPage->domain ?: \Environment::get('host')) . TL_PATH . '/';
return $domain . \Controller::generateFrontendUrl($objPage->row(), '', $objPage->language);
}
break;
// Link to an article
// Link to an article
case 'article':
if (($objArticle = \ArticleModel::findByPk($objItem->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
return $strBase . ampersand(\Controller::generateFrontendUrl($objPid->row(), '/articles/' . (!\Config::get('disableAlias') && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id)));
}
break;
}
// handle encoded characters %D9%86
$strUrl = rawurldecode($strUrl);
// Link to the default page
return $strBase . sprintf($strUrl, $objItem->alias != '' && !\Config::get('disableAlias') ? $objItem->alias : $objItem->id);
}
示例15: generateNewsUrl
/**
* Generate a URL and return it as string
*
* @param \NewsModel $objItem
* @param boolean $blnAddArchive
*
* @return string
*/
protected function generateNewsUrl($objItem, $blnAddArchive = false)
{
$strCacheKey = 'id_' . $objItem->id;
// Load the URL from cache
if (isset(self::$arrUrlCache[$strCacheKey])) {
return self::$arrUrlCache[$strCacheKey];
}
// Initialize the cache
self::$arrUrlCache[$strCacheKey] = null;
switch ($objItem->source) {
// Link to an external page
case 'external':
if (substr($objItem->url, 0, 7) == 'mailto:') {
self::$arrUrlCache[$strCacheKey] = \StringUtil::encodeEmail($objItem->url);
} else {
self::$arrUrlCache[$strCacheKey] = ampersand($objItem->url);
}
break;
// Link to an internal page
// Link to an internal page
case 'internal':
if (($objTarget = $objItem->getRelated('jumpTo')) !== null) {
self::$arrUrlCache[$strCacheKey] = ampersand($this->generateFrontendUrl($objTarget->row()));
}
break;
// Link to an article
// Link to an article
case 'article':
if (($objArticle = \ArticleModel::findByPk($objItem->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
self::$arrUrlCache[$strCacheKey] = ampersand($this->generateFrontendUrl($objPid->row(), '/articles/' . (!\Config::get('disableAlias') && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id)));
}
break;
}
// Link to the default page
if (self::$arrUrlCache[$strCacheKey] === null) {
$objPage = \PageModel::findByPk($objItem->getRelated('pid')->jumpTo);
if ($objPage === null) {
self::$arrUrlCache[$strCacheKey] = ampersand(\Environment::get('request'), true);
} else {
self::$arrUrlCache[$strCacheKey] = ampersand($this->generateFrontendUrl($objPage->row(), (\Config::get('useAutoItem') && !\Config::get('disableAlias') ? '/' : '/items/') . (!\Config::get('disableAlias') && $objItem->alias != '' ? $objItem->alias : $objItem->id)));
}
// Add the current archive parameter (news archive)
if ($blnAddArchive && \Input::get('month') != '') {
self::$arrUrlCache[$strCacheKey] .= (\Config::get('disableAlias') ? '&' : '?') . 'month=' . \Input::get('month');
}
}
return self::$arrUrlCache[$strCacheKey];
}