我正在使用Offiria(基于joomla的社交网络脚本),当我单击链接“显示所有评论”以查看链接下所有已发布的评论时,我在第一条评论上方收到以下错误。该功能可以工作,因此所有评论都会扩展,我可以看到所有评论,但错误也在那里。
严格标准:非静态方法StreamComment::getCommentsHTML()不应该被静态调用,假设$this来自第31行的C:\节目文件\放大器\www\offiria\组件\com_stream\控制器\comment.php中不兼容的上下文
这是文件中comment.php第31行:
public function showall()
{
$stream_id = JRequest::getVar('message_id');
$html = StreamComment::getCommentsHTML($stream_id);
header('Content-Type: text/html; charset=UTF-8');
echo $html;
exit;
}
我曾尝试禁用我的php.ini中的所有错误报告选项,但错误不断出现。我还尝试将上述代码更改为“公共静态函数显示()”,但我得到一个错误,即严格标准:非静态方法StreamComment::getCommentsHTML()不应静态调用。
如果能提前得到帮助,我将不胜感激。
这是完整的comment.php
<?php
/**
* @version 1.0.0
* @package com_administrator
* @copyright Copyright (C) 2011 - 2013 Slashes & Dots Sdn Bhd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @author Offiria Team
*/
// No direct access.
defined('_JEXEC') or die;
jimport('joomla.application.controller');
class StreamControllerComment extends JController
{
/**
*
*/
public function display($cachable = false, $urlparams = false){
parent::display( null );
}
/**
* Return HTML of all
*/
/**public function showall()
{
$stream_id = JRequest::getVar('message_id');
$html = StreamComment::getCommentsHTML($stream_id);
header('Content-Type: text/html; charset=UTF-8');
echo $html;
exit;
}
/**
* Add message
*/
public function add()
{
$user = JXFactory::getUser();
// Store stream
$comment = JTable::getInstance( 'Comment' , 'StreamTable' );
$message = JTable::getInstance( 'Stream' , 'StreamTable' );
$message->load(JRequest::getVar('stream_id'));
$user_id = JRequest::getVar('anon', false) ? JUserHelper::getUserId('anon') : $user->id;
// People need to be able to read the message to add comment
if( !$user->authorise('stream.message.read', $message) ){
// No reason this code would ever get here!
exit;
}
$comment->bind( JRequest::get('POST', JREQUEST_ALLOWRAW) );
$comment->raw = json_encode( JRequest::get('POST', JREQUEST_ALLOWRAW) );
$comment->user_id = $user_id;
$comment->group_id = $message->group_id;
$comment->store();
// Update group stats, if it is a group message
if( !empty($comment->group_id)){
$group = JTable::getInstance( 'Group' , 'StreamTable' );
$group->load($comment->group_id);
$group->setParam('last_comment', $comment->id);
$group->store();
}
// Trigger Notification
StreamNotification::trigger( 'profile_post_comment', $comment );
// If the updated date is set further than the current date, it is a pinned stream item and shouldn't be updated
$now = new JDate();
$updated = new JDate($message->updated);
$preventUpdate = ($updated->toUnix() > $now->toUnix()); // Check pinned item status too? For now... naa
// Update stream stats. Recalculate the count
$this->_recalculateCommentCount($comment->stream_id, $preventUpdate);
// Get the HTML code to append
$tmpl = new StreamTemplate();
header('Content-Type: text/html; charset=UTF-8');
echo $tmpl->set('comment', $comment)->fetch('comment.item');
exit;
}
/**
* Delete a message
*/
public function delete(){
$my = JXFactory::getUser();
$id = JRequest::getVar('comment_id');
$oldComment = '';
$comment = JTable::getInstance( 'Comment' , 'StreamTable' );
$comment->load($id);
if( !$my->authorise('stream.comment.delete', $comment) ){
// No reason this code would ever get here!
exit;
}
$oldComment = $comment->comment;
$comment->delete();
$this->_recalculateCommentCount($comment->stream_id, true);
// Send back the original comment if it is the last one
$data = array();
$data['comment'] = $oldComment;
header('Content-Type: text/json');
echo json_encode($data);
exit;
}
private function _recalculateCommentCount($message_id, $preventUpdate = false)
{
// Update stream stats. Recalculate the count
$model = StreamFactory::getModel('stream');
$stream = JTable::getInstance('Stream', 'StreamTable');
$stream->load( $message_id ) ;
$stream->setParam('comment_count', $model->countComments(array('stream_id' => $stream->id)));
$stream->store( $preventUpdate );
}
/**
* Like a comment
*/
public function like()
{
$user = JXFactory::getUser();
$comment_id = JRequest::getVar('comment_id');
$comment = JTable::getInstance('Comment', 'StreamTable');
$comment->load($comment_id);
$comment->like();
$comment->store(true);
$data = array();
$data['label'] = JText::_('COM_STREAM_UNLIKE_LABEL');
$data['count'] = $comment->getLikeCount();
header('Content-Type: text/json');
echo json_encode($data);
exit;
}
/**
* Unlike a comment
*/
public function unlike()
{
$user = JXFactory::getUser();
$comment_id = JRequest::getVar('comment_id');
$comment = JTable::getInstance('Comment', 'StreamTable');
$comment->load($comment_id);
$comment->unlike();
$comment->store(true);
$data = array();
$data['label'] = JText::_('COM_STREAM_LIKE_LABEL');
$data['count'] = $comment->getLikeCount();
header('Content-Type: text/json');
echo json_encode($data);
exit;
}
/**
* Get all current likes
*/
public function showlikes()
{
$comment_id = JRequest::getVar('comment_id');
$comment = JTable::getInstance('Comment', 'StreamTable');
$comment->load($comment_id);
$likes = ($comment->likes) ? explode(',', $comment->likes ) : null;
$likeUsers = array();
$likesHTML = '';
if ($likes) {
foreach ($likes as $key => $val) {
$likeUsers[] = JXFactory::getUser($val)->name;
}
$likesHTML = implode(", ", $likeUsers);
$likesHTML = JXString::isPlural(count($likeUsers)) ? JText::sprintf('COM_STREAM_LIKE_THIS_MANY_LIST', $likesHTML) : JText::sprintf('COM_STREAM_LIKE_THIS_LIST', $likesHTML);
}
$data['likes'] = $likesHTML;
header('Content-Type: text/json');
echo json_encode($data);
exit;
}
}
这里发生的事情是这个函数被静态调用了:
StreamComment::showall(); // Static Call
但它被定义为非静态方法,这意味着PHP希望它被这样调用:
$obj = new StreamComment();
$obj->showall(); // Dynamic Call
如果这是调用此方法的唯一位置,或者始终以静态方式调用此方法,则可以通过将该方法重新定义为静态来解决此问题:
public static function showall() // Added the "static" keyword
{
// [..code..]
}
希望这有帮助:)
嗨,我有以下型号。 场馆模型 调查模型 当我试图获得一个地点的调查,我得到以下错误。 非静态方法 App\Venues::survey() 不应静态调用,假设$this来自不兼容的上下文 我已经在 Laravel 5.1 中创建了与此相同的模型和关系,而没有此问题。我想知道我是否在 Laravel 5.2 中遗漏了某些内容。
我在我的网站上有这些错误: 严格的标准:第17行的 /home/kmxsiksf/www/modules/mod_jumi/mod_jumi.php中不应该静态调用非静态方法modJumiHelper::getCodeWritten() 严格标准:非静态方法modJumiHelper::getStorageSource()不应在/home/kmxsiksf/www/modules/mod_jumi
我在magento日志中得到这个错误: 严格注意:非静态方法 Mage_Catalog_Block_Product:getPriceHtml() 不应静态调用,假设$this来自第 23 行 /home/edistico/domains/fujitsu-skener.si/public_html/app/design/frontend/base/default/template/callforpr
问题内容: 我有以下php。但是,当我看到index.php时,出现以下错误消息。 严格的标准:非静态方法Page :: getInstanceByName()不应在第12行的/var/www/webworks/index.php中被静态调用 我希望有人可以告诉我如何解决该问题。 index.php ww.incs / common.php ww.incs / basics.php Page.ph
我最近对 PHP 5.4 进行了更新,但收到有关静态和非静态代码的错误。 这是错误: 这是第371行: 我希望有人能帮忙。
我正在使用存储库模式并尝试建立模型之间的关系。当我尝试运行存储()方法(在控制器中),该方法试图使用用户()方法(与方模型建立关系)时,我收到以下错误消息: 非静态方法不应该静态调用::user(),假设$this来自不兼容的上下文 我不明白为什么在尝试运行user()relationship方法时会出现此错误,但所有其他方法(包括$this- 以下是相关代码: