1
votes

All,

I'm trying to develop my first Joomla component and I'm following the MVC tutorial at here.

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_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":"[email protected]","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);

  2. The main component code mysite/component/com_abc/abc.php is;

    <?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:

    <?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:

    <?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:

    <?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

Appreciate if you could help me in resolving the issue.

Many thanks.

2

2 Answers

1
votes
// 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:

  • This function is provide as a default implementation, in most cases
  • you will need to override it in your own controllers.
1
votes

I was having the same issue. Review all your class names and make sure that they are following Joomla naming rules. Your controller must be named AbcController inside site folder. Review also your views I think they will cause problems to you too