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

2022-01-06 00:00:00 web php joomla

我似乎什么都试过了.我正在尝试学习如何创建一个新组件,目前我的文件夹结构如下所示(请注意该组件已安装).

i seem to have tried everything. I am trying to learn how to create a new component and currently my folder structure looks like this (please note that the component does install).

这是我的文件夹结构图:

This is a picture of my folder structure:

我关闭了其中的一些,因为我发现它无关紧要,但是如果您需要查看其中的内容,请告诉我.

Ive closed some of it because i found it irelevant but please if you need to see whats inside of them please let me know.

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

as i stated above the component does install without problems. however when i try to access it i get the following error:

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

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

Now the file it is refering to is this one:

    <?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();

我知道这很难说,但有人知道问题出在哪里吗?

I know it can be hard to tell but does anyone know what the problem might be?

推荐答案

请查看Joomla版本

Please check Joomla version

在 3.X 中

   $controller  = JControllerLegacy::getInstance('HelloWorld');

在 2.X 中

   $controller = JController::getInstance('HelloWorld');

相关文章