简体   繁体   English

joomla错误:#0无效的控制器类:

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

All, 所有,

I'm trying to develop my first Joomla component and I'm following the MVC tutorial at here . 我正在尝试开发我的第一个Joomla组件,并且在这里关注MVC教程。

But I could not progress much because I'm getting the following error. 但是,由于出现以下错误,我无法取得太大进展。

#0 Invalid controller class: AbcController

I've enabled the debug trace and it's giving an error at the following line: 我启用了调试跟踪,并在以下行中给出了错误:

JControllerLegacy::getInstance()

Needless to mention, I have already spent quite some time searching for a solution but could not find any solution. 不用说,我已经花了很多时间寻找解决方案,但是找不到任何解决方案。

I'm working on: 我正在尝试:

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

I followed following steps: 我遵循以下步骤:

  1. Created an entry in extensions table. 在扩展表中创建了一个条目。

    INSERT INTO abc . 插入abc abc_extensions ( extension_id , name , type , element , folder , client_id , enabled , access , protected , manifest_cache , params , custom_data , system_data , checked_out , checked_out_time , ordering , state ) VALUES (701, 'com_abc', 'component', 'com_abc', '', 1, 1, 1, 0, '{"name":"com_abc","type":"component","creationDate":"July 2014","author":"ABC Project","copyright":"(C) 2005 - 2014 Open Source Matters. All rights reserved.\\n\\t","authorEmail":"admin@joomla.org","authorUrl":"www.abc.org","version":"1.0.0","description":"COM_ABC_DESCRIPTION","group":""}', '{"enabled":"0","show_date":"1"}', '', '', 0, '0000-00-00 00:00:00', 0, 0); 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. The main component code mysite/component/com_abc/abc.php is; 主要组件代码为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. The controller code mysite/component/com_abc/controller.php is: 控制器代码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. The view file mysite/component/com_abc/views/main/view.html.php contains: 视图文件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. The template file mysite/component/com_abc/views/main/tmpl/default.php contains: 模板文件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. The view is called using index.php?option=com_abc&view=main 使用index.php?option = com_abc&view = main调用该视图

Appreciate if you could help me in resolving the issue. 谢谢您能帮助我解决问题。

Many thanks. 非常感谢。

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

Not sure what you are doing there, there is not a file like that, the controller classes new and old are in their respective controller folders. 不确定您在做什么,没有类似的文件,新的和旧的控制器类位于各自的控制器文件夹中。 But they are all autoloaded anyway so that's not your problem. 但是无论如何它们都是自动加载的,所以这不是您的问题。

More importantly I suggest you put some code in your controller, specifically a display method that sets the default view for your component. 更重要的是,我建议您在控制器中放入一些代码,特别是一种显示方法,该方法为组件设置默认视图。 Look at any core component and you'll see what I mean. 看看任何核心组件,您都会明白我的意思。 As it says in the JControllerLegacy::display doc blocks: 就像在JControllerLegacy :: display doc块中所说的:

  • This function is provide as a default implementation, in most cases 在大多数情况下,此功能作为默认实现提供
  • you will need to override it in your own controllers. 您将需要在自己的控制器中覆盖它。

I was having the same issue. 我有同样的问题。 Review all your class names and make sure that they are following Joomla naming rules. 查看您所有的类名,并确保它们遵循Joomla命名规则。 Your controller must be named AbcController inside site folder. 您的控制器必须在站点文件夹中命名为AbcController。 Review also your views I think they will cause problems to you too 还要回顾您的观点,我认为它们也会给您带来问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM