与 XF\Pub\Controller\AbstractController 相关的类型错误
TypeError related to XF\Pub\Controller\AbstractController
免责声明:我是 XenForo 2.X 编程新手,请放轻松。
An exception occurred: [TypeError] Argument 1 passed to
Pages\Providers::getData() must be an instance of
XF\Pub\Controller\AbstractController, string given in
src/addons/Pages/Providers.php on line 23
Pages\Providers::getData()
call_user_func() in src/XF/Template/Templater.php at line 1382
XF\Template\Templater->callback() in internal_data/code_cache/templates/l1/s2/public/_page_node.100.php at line 13
XF\Template\Templater->{closure}() in src/XF/Template/Templater.php at line 1294
XF\Template\Templater->renderTemplate() in src/XF/Template/Templater.php at line 1367
XF\Template\Templater->includeTemplate() in internal_data/code_cache/templates/l1/s2/public/page_view.php at line 82
XF\Template\Templater->{closure}() in src/XF/Template/Templater.php at line 1294
XF\Template\Templater->renderTemplate() in src/XF/Template/Template.php at line 24
XF\Template\Template->render() in src/XF/Mvc/Renderer/Html.php at line 48
XF\Mvc\Renderer\Html->renderView() in src/XF/Mvc/Dispatcher.php at line 418
XF\Mvc\Dispatcher->renderView() in src/XF/Mvc/Dispatcher.php at line 400
XF\Mvc\Dispatcher->renderReply() in src/XF/Mvc/Dispatcher.php at line 360
XF\Mvc\Dispatcher->render() in src/XF/Mvc/Dispatcher.php at line 53
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2177
XF\App->run() in src/XF.php at line 390
XF::runApp() in index.php at line 20
我不知道我做错了什么...这是我目前的攻击计划,我有一段非常短的代码(下面包含一个函数),我想在使用 PHP 回调的 XenForo 页面。回调的标准是使用控制器和回复参考,如 xf:
所述
\XF\Pub\Controller\AbstractController $controller
控制器
实例。从这里您可以检查请求、响应等。
\XF\Mvc\Reply\AbstractReply &$reply
页面标准回复
控制器。
作为页面的节点中包含的回调是 Pages\Providers::getData()
。但是 运行 所以给了我 TypeError。根据我的理解,$controller
参数 1 的类型不正确是对我大喊大叫,但如何呢?我的代码甚至不需要它。任何关于如何解决这个问题的想法将不胜感激!谢谢。
<?php
namespace Pages;
class Providers
{
/**
* @param \XF\Pub\Controller\AbstractController $controller
* @param \XF\Mvc\Reply\AbstractReply &$reply
*/
public static function getData(
\XF\Pub\Controller\AbstractController $controller,
\XF\Mvc\Reply\AbstractReply &$reply
) {
if ($reply instanceof \XF\Mvc\Reply\View) {
$finder = \XF::finder('XF:Thread');
$thread = $finder->where('thread_id', 1)->fetchOne();
$firstPost = \XF::app()->finder('XF:Post')->where('post_id', $thread['first_post_id'])->fetchOne();
$viewParams = [
'title' => $thread['title'],
'message' => $firstPost['message']
];
// return $firstPost['message'];
$reply->setParam('providers', $viewParams);
}
}
}
我不知道什么是 xenforo
。但是您的错误消息清楚地表明:
An exception occurred: [TypeError] Argument 1 passed to
Pages\Providers::getData() must be an instance of
XF\Pub\Controller\AbstractController, string given in
src/addons/Pages/Providers.php on line 23
在您的代码第 23 行中,我认为是这个:
$reply->setParam('providers', $viewParams);
所以只需传递第一个参数而不是字符串,而是您拥有的实例:
$reply->setParam($controller, $viewParams);
免责声明:我是 XenForo 2.X 编程新手,请放轻松。
An exception occurred: [TypeError] Argument 1 passed to
Pages\Providers::getData() must be an instance of
XF\Pub\Controller\AbstractController, string given in
src/addons/Pages/Providers.php on line 23
Pages\Providers::getData()
call_user_func() in src/XF/Template/Templater.php at line 1382
XF\Template\Templater->callback() in internal_data/code_cache/templates/l1/s2/public/_page_node.100.php at line 13
XF\Template\Templater->{closure}() in src/XF/Template/Templater.php at line 1294
XF\Template\Templater->renderTemplate() in src/XF/Template/Templater.php at line 1367
XF\Template\Templater->includeTemplate() in internal_data/code_cache/templates/l1/s2/public/page_view.php at line 82
XF\Template\Templater->{closure}() in src/XF/Template/Templater.php at line 1294
XF\Template\Templater->renderTemplate() in src/XF/Template/Template.php at line 24
XF\Template\Template->render() in src/XF/Mvc/Renderer/Html.php at line 48
XF\Mvc\Renderer\Html->renderView() in src/XF/Mvc/Dispatcher.php at line 418
XF\Mvc\Dispatcher->renderView() in src/XF/Mvc/Dispatcher.php at line 400
XF\Mvc\Dispatcher->renderReply() in src/XF/Mvc/Dispatcher.php at line 360
XF\Mvc\Dispatcher->render() in src/XF/Mvc/Dispatcher.php at line 53
XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2177
XF\App->run() in src/XF.php at line 390
XF::runApp() in index.php at line 20
我不知道我做错了什么...这是我目前的攻击计划,我有一段非常短的代码(下面包含一个函数),我想在使用 PHP 回调的 XenForo 页面。回调的标准是使用控制器和回复参考,如 xf:
所述\XF\Pub\Controller\AbstractController $controller
控制器 实例。从这里您可以检查请求、响应等。\XF\Mvc\Reply\AbstractReply &$reply
页面标准回复 控制器。
作为页面的节点中包含的回调是 Pages\Providers::getData()
。但是 运行 所以给了我 TypeError。根据我的理解,$controller
参数 1 的类型不正确是对我大喊大叫,但如何呢?我的代码甚至不需要它。任何关于如何解决这个问题的想法将不胜感激!谢谢。
<?php
namespace Pages;
class Providers
{
/**
* @param \XF\Pub\Controller\AbstractController $controller
* @param \XF\Mvc\Reply\AbstractReply &$reply
*/
public static function getData(
\XF\Pub\Controller\AbstractController $controller,
\XF\Mvc\Reply\AbstractReply &$reply
) {
if ($reply instanceof \XF\Mvc\Reply\View) {
$finder = \XF::finder('XF:Thread');
$thread = $finder->where('thread_id', 1)->fetchOne();
$firstPost = \XF::app()->finder('XF:Post')->where('post_id', $thread['first_post_id'])->fetchOne();
$viewParams = [
'title' => $thread['title'],
'message' => $firstPost['message']
];
// return $firstPost['message'];
$reply->setParam('providers', $viewParams);
}
}
}
我不知道什么是 xenforo
。但是您的错误消息清楚地表明:
An exception occurred: [TypeError] Argument 1 passed to Pages\Providers::getData() must be an instance of XF\Pub\Controller\AbstractController, string given in src/addons/Pages/Providers.php on line 23
在您的代码第 23 行中,我认为是这个:
$reply->setParam('providers', $viewParams);
所以只需传递第一个参数而不是字符串,而是您拥有的实例:
$reply->setParam($controller, $viewParams);