Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6114273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:57:20+00:00 2026-05-23T14:57:20+00:00

My structure has component.php in the root of my component. I am using the

  • 0

My structure has component.php in the root of my component. I am using the http://www.notwebdesign.com/joomla-component-creator/j15/index.php
I feel the need to have multiple controllers to have cleaner code as I have around 12 tasks to be run. I am using multiple models and need to have multiple controllers.

Anyone who can point me in the right direction? Sample code highly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:57:20+00:00Added an answer on May 23, 2026 at 2:57 pm

    You need to make a folder in your component’s main directory (e.g. components/com_mycom/controllers/…)

    Then the main file of my component (it should be called “mycom.php” using the example from above) has code that looks like this:

    // no direct access
    defined( '_JEXEC' ) or die( 'Restricted access' );
    
    // load a constants file for use throughout the component
    require_once(JPATH_COMPONENT.DS.'lib'.DS.'constants.php');
    
    // fetch the view
    $view = JRequest::getVar( 'view' , 'null' );
    
    // use the view to fetch the right controller
    require_once( JPATH_COMPONENT.DS.'controllers'.DS.$view.'.php' );
    
    // initiate the contoller class and execute the controller
    $controllerClass = 'MycomController'.ucfirst($view);
    $controller = new $controllerClass;
    // call the display function in the controller by default - add a task param to the url to call another function in the controller
    $controller->execute( JRequest::getVar( 'task', 'display' ) ); 
    $controller->redirect();
    

    Then for your controllers in your controllers directory your code would be as normal e.g.

    defined( '_JEXEC' ) or die( 'Restricted access' );
    jimport('joomla.application.component.controller');
    
    class MycomControllerAdd extends JController
    {
    
      function display() { 
        $viewLayout  = JRequest::getVar( 'tmpl', 'add' );
        $view = &$this->getView( 'add', 'html' );
        $model = &$this->getModel( 'add' );
        $view->setModel( $model, true );
        $view->setLayout( $viewLayout );
        $view->addStuff();
      }
    
      ...
    

    A url that would call this would look like so:

    http://somedomain.com/index.php?option=com_mycom&view=add
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using windows, Mysql DB, PHP I am building the Joomla Component whose
Question: What ruleset do I need to do the following redirects: [1] http://www.xyzblog.com/foo/bar.php =>
I'm writing a program where each component has an inheritance structure has three levels...
I'm building a gui component that has a tree-based data model (e.g. folder structure
I have a structure defined in IDL. This structure has following members: { BSTR
I have an entity model where the base class in an inheritance structure has
I'm working in c#. I have a sorted List of structures. The structure has
I have a structure which has 3 identifier fields and one value field. I
I have a database structure that has a Person table which contains fields such
I want to write a structure which has a list of integer id. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.