免责声明:我是 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
我不知道我做错了什么......这是我目前的攻击计划,我有一个非常短的代码片段(下面包含一个函数),我想在 XenForo 页面中使用 PHP 调用它打回来。回调的标准是使用控制器和 xf 所述的回复引用:
\XF\Pub\Controller\AbstractController $controller
控制器实例。从这里你可以检查请求、响应等。\XF\Mvc\Reply\AbstractReply &$reply
来自页面控制器的标准回复。
包含在 Page 的节点中的回调是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);
}
}
}