Call to undefined method JController::getInstance(

2019-04-08 16:22发布

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:

enter image description here

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?

标签: php web joomla
3条回答
对你真心纯属浪费
2楼-- · 2019-04-08 16:50

Please check Joomla version

In 3.X

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

In 2.X

   $controller = JController::getInstance('HelloWorld');
查看更多
唯我独甜
3楼-- · 2019-04-08 16:55

The error message says that the JController does not have the static method getInstance().

查看更多
叼着烟拽天下
4楼-- · 2019-04-08 17:00

You don't say what version you are on but you probably want JControllerLegacy for J3 unless you are building with the new MVC. JController does not have a getInstance() Method but JControllerLegacy does see github.com/joomla/joomla-cms/blob/master/libraries/joomla/controller

查看更多
登录 后发表回答