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

Call to undefined method JController::getInstance()(调用未定义的方法 JController::getInstance())
本文介绍了调用未定义的方法 JController::getInstance()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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');

这篇关于调用未定义的方法 JController::getInstance()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)