【问题标题】:php error Fatal error: Call to a member function get()php错误致命错误:调用成员函数get()
【发布时间】:2015-09-10 13:04:07
【问题描述】:

我收到如下错误:

注意:未定义的属性:CedTagViewTag::$pagination

致命错误:调用成员函数 get()

这是我收到错误的代码部分:

(($this->show_pagination == 1 || ($this->show_pagination == 2)) && ($this->pagination->get('pages.total') > 1)) { ?>
<div class="pagination">

我该如何解决? 这是完整的代码

defined('_JEXEC') or die('Restricted access');

require_once (JPATH_SITE . '/components/com_content/helpers/route.php');
require_once JPATH_SITE . '/components/com_cedtag/helpers/themes.php';

// to reuse components/com_content/views/category/tmpl/blog_item.php
// when doing later $this->loadTemplate('item');
$this->addTemplatePath(JPATH_SITE . '/components/com_content/views  /category/tmpl');
JHtml::addIncludePath(JPATH_SITE . '/components/com_cedtag/helpers');
//blog_item.php use icon.php
JHtml::addIncludePath(JPATH_SITE . '/components/com_content/helpers');

$document = JFactory::getDocument();
$document->addStyleSheet('media/com_cedtag/css/blog.css');

$cedTagsHelper = new CedTagsHelper();
if ($this->tagDescription) {
      $document->setDescription($cedTagsHelper->truncate($this->tagDescription));
} else {
$document->setDescription($cedTagsHelper->truncate($this->tag));
}

$document->setTitle($this->title);
$document->setMetadata('keywords', $this->tag);

$CedTagThemes = new CedTagThemes();
$CedTagThemes->addCss();

?>

<h1><?php echo JText::_('COM_CEDTAG_POSTS_TAGGED') . " " . JText::_('\'') . $this->tag . JText::_('\'') ?></h1>
<?php if (isset($this->showDescription) && $this->showDescription && ($this->tagDescription != null)) { ?>
<div class="category-desc">
<?php echo $this->tagDescription; ?>
</div>
<?php
}
?>
<?php if (isset($this->ads_top_use) && $this->ads_top_use) { ?>
<div class="cedTagAdsTopContent">
<?php  echo $this->ads_top_content; ?>
</div>
<?php } ?>
<?php
if (isset($this->results) && !empty($this->results)) {
foreach ($this->results as $item) {
    $this->item = & $item;
    echo $this->loadTemplate('item');
}
} ?>

<?php
if (isset($this->ads_bottom_use) && $this->ads_bottom_use) {
?>
<div class="cedTagAdsBottomContent">
<?php  echo $this->ads_bottom_content; ?>
</div>
<?php
}
?>

<?php if (($this->show_pagination == 1 || ($this->show_pagination == 2)) && ($this->pagination->get('pages.total') > 1)) { ?>
<div class="pagination">
<?php if ($this->show_pagination_results) { ?>
<p class="counter">
    <?php echo $this->pagination->getPagesCounter(); ?>
</p>
<?php } ?>
<?php echo $this->pagination->getPagesLinks(); ?>
</div>
<?php } ?>

【问题讨论】:

  • 那里有什么框架吗??
  • $pagination 是如何声明的以及在哪里声明的?

标签: php mysql


【解决方案1】:

您收到错误的原因可以从逻辑上解释。

注意:未定义的属性:CedTagViewTag::$pagination

是因为“分页”属性(我认为您正在静态访问它?)没有定义,它不存在。如果您尝试访问尚未定义的变量,那将是同一件事(出于示例的所有目的)。

致命错误:调用成员函数 get()

虽然这可能不相关,但可以用前面的错误来解释。是相关的。导致它的部分在您的if 条件中:

&amp;&amp; ($this-&gt;pagination-&gt;get('pages.total') &gt; 1))

你在pagination 上调用get() 方法,那么你会得到这个错误,因为你试图在一个未定义的属性上调用一个方法!为了解决这个问题,我建议正确查看对象以及它是如何被实例化的并解析pagination,因为它显然是未定义的,并且包括哪些框架或如何实例化分页以获得更清晰的画面和更好的答案。

【讨论】:

    猜你喜欢
    • 2015-11-05
    • 1970-01-01
    • 1970-01-01
    • 2011-08-22
    • 1970-01-01
    • 2012-09-29
    • 2014-02-05
    • 2014-04-29
    • 2015-09-14
    相关资源
    最近更新 更多