调用未定义的方法JController :: getInstance()

Mar*_*sen 7 php joomla web

我似乎已经尝试了一切.我正在尝试学习如何创建一个新组件,目前我的文件夹结构看起来像这样(请注意该组件确实安装).

这是我的文件夹结构的图片:

在此输入图像描述

我关闭了一些,因为我发现它是相关的,但如果你需要看到里面的内容,请告诉我.

正如我上面所说,组件确实安装没有问题.但是,当我尝试访问它时,我收到以下错误:

Fatal error: Call to undefined method JController::getInstance() in /home/marcrasm/public_html/Joomla/administrator/components/com_helloworld/helloworld.php on line 13
Run Code Online (Sandbox Code Playgroud)

现在它引用的文件就是这个:

    <?php
defined('_JEXEC') or die ('Restricted access');

jimport('joomla.application.component.controller');

$doc = JFactory::getDocument();
$doc->addScript("/components/com_helloworld/js/jquery.js");
$doc->addScript("/components/com_helloworld/js/com_helloworld_script.js");
$doc->addStyleSheet("/components/com_helloworld/css/com_helloworld_layout.css");

// gets the instance of the controller
// Get an instance of the controller prefixed by HelloWorld
$controller = JController::getInstance('HelloWorld');

// Perform the Request task
$input = JFactory::getApplication()->input;
$controller->execute($input->getCmd('task'));

// Redirect if set by the controller
$controller->redirect();
Run Code Online (Sandbox Code Playgroud)

我知道这很难说,但有谁知道问题可能是什么?

Sau*_*tel 22

请检查Joomla版本

在3.X

   $controller  = JControllerLegacy::getInstance('HelloWorld');
Run Code Online (Sandbox Code Playgroud)

在2.X

   $controller = JController::getInstance('HelloWorld');
Run Code Online (Sandbox Code Playgroud)


Eli*_*lin 5

您没有说明您使用的是什么版本,但除非您使用新的MVC构建,否则您可能希望J3的JControllerLegacy.JController没有getInstance()方法,但JControllerLegacy确实看到了github.com/joomla/joomla-cms/blob/master/libraries/joomla/controller