2013-07-27 93 views
5

我似乎已經嘗試了一切。我正在嘗試學習如何創建一個新組件,目前我的文件夾結構看起來像這樣(請注意組件會安裝)。調用未定義的方法JController :: getInstance()

這是我的文件夾結構的圖片:

enter image description here

伊夫關閉了一些的,因爲我發現它irelevant但請,如果你需要看到什麼他們裏面請讓我知道。

正如我上面所述,組件的安裝沒有問題。然而,當我試圖訪問它,我得到以下錯誤:

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

現在是闖民宅的文件是這個:

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

我知道這很難說,但沒有人知道這個問題可能是什麼?

回答

18

請檢查的Joomla版本

在3.X

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

在2.X

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

哈哈我有兩個網站一個2.5和一個3.0。所以我在3.0上工作了一週,當我返回來修復2.5中的某些內容時......等等!崩潰! :P – themis

0

錯誤消息說JController沒有靜態方法getInstance()

+0

是啊,我知道;),但根據的Joomla文檔的exteded類確實有該方法 –

+0

所以那麼請你從JControll添加相關的代碼呃你的問題? –

+0

恩?從哪裏Jcontroller是Joomla lib的一部分不是嗎?就像我導入它的時候一樣 –

5

你不會說你是哪個版本,但你可能想要J3的JControllerLegacy,除非你正在用新的MVC構建。 JController沒有一個getInstance()方法,但JControllerLegacy沒有看到github.com/joomla/joomla-cms/blob/master/libraries/joomla/controller

相關問題