簡體   English   中英

joomla錯誤:#0無效的控制器類:

[英]joomla error : #0 Invalid controller class:

所有,

我正在嘗試開發我的第一個Joomla組件,並且在這里關注MVC教程。

但是,由於出現以下錯誤,我無法取得太大進展。

#0 Invalid controller class: AbcController

我啟用了調試跟蹤,並在以下行中給出了錯誤:

JControllerLegacy::getInstance()

不用說,我已經花了很多時間尋找解決方案,但是找不到任何解決方案。

我正在嘗試:

OS: Windows 8.1
PHP version: 5.5.6
MySQL version: 5.6.16
Joomla version: Joomla! 3.3.1 Stable

我遵循以下步驟:

  1. 在擴展表中創建了一個條目。

    插入abc abc_extensionsextension_idnametypeelementfolderclient_id ,已enabledaccessprotectedmanifest_cacheparamscustom_datasystem_datachecked_outchecked_out_timeorderingstate )VALUES(701,'com_abc','component','com_abc ','',1,1,1,0,'{“ name”:“ com_abc”,“ type”:“ component”,“ creationDate”:“ 2014年7月”,“ author”:“ ABC Project”,“ copyright“:”(C)2005-2014 Open Source Matters。保留所有權利。\\ n \\ t“,” authorEmail“:” admin@joomla.org“,” authorUrl“:” www.abc.org“,” version “:” 1.0.0“,”描述“:” COM_ABC_DESCRIPTION“,”組“:”“}','{”啟用“:” 0“,” show_date“:” 1“}',``,'' ,0,'0000-00-00 00:00:00',0,0);

  2. 主要組件代碼為mysite / component / com_abc / abc.php;

     <?php // No direct access to this file defined('_JEXEC') or die('Restricted access'); // import joomla controller library jimport('joomla.application.component.controller'); // Get an instance of the controller prefixed by HelloWorld $controller = JControllerLegacy::getInstance('Abc'); // Perform the Request task $input = JFactory::getApplication()->input; $controller->execute($input->getCmd('task')); // Redirect if set by the controller $controller->redirect(); 
  3. 控制器代碼mysite / component / com_abc / controller.php是:

     <?php // No direct access to this file defined('_JEXEC') or die('Restricted access'); // import Joomla controller library jimport('joomla.application.component.controller'); /** * Hello World Component Controller */ class AbcController extends JControllerLegacy { } 
  4. 視圖文件mysite / component / com_abc / views / main / view.html.php包含:

     <?php // No direct access to this file defined('_JEXEC') or die('Restricted access'); // import Joomla view library jimport('joomla.application.component.view'); /** * HTML View class for the HelloWorld Component */ class AbcViewMain extends JViewLegacy { // Overwriting JView display method function display($tpl = null) { // Assign data to the view $this->msg = 'Hello World'; // Display the view parent::display($tpl); } } 
  5. 模板文件mysite / component / com_abc / views / main / tmpl / default.php包含:

     <?php // No direct access to this file defined('_JEXEC') or die('Restricted access'); ?> <h1><?php echo $this->msg; ?></h1> 
  6. 使用index.php?option = com_abc&view = main調用該視圖

謝謝您能幫助我解決問題。

非常感謝。

// import Joomla controller library
jimport('joomla.application.component.controller');

不確定您在做什么,沒有類似的文件,新的和舊的控制器類位於各自的控制器文件夾中。 但是無論如何它們都是自動加載的,所以這不是您的問題。

更重要的是,我建議您在控制器中放入一些代碼,特別是一種顯示方法,該方法為組件設置默認視圖。 看看任何核心組件,您都會明白我的意思。 就像在JControllerLegacy :: display doc塊中所說的:

  • 在大多數情況下,此功能作為默認實現提供
  • 您將需要在自己的控制器中覆蓋它。

我有同樣的問題。 查看您所有的類名,並確保它們遵循Joomla命名規則。 您的控制器必須在站點文件夾中命名為AbcController。 還要回顧您的觀點,我認為它們也會給您帶來問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM