[英]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
我遵循以下步骤:
在扩展表中创建了一个条目。
插入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”:“ 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);
主要组件代码为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();
控制器代码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 { }
视图文件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); } }
模板文件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>
使用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.