[FIXED] Unable to call specific controller

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
adam.hughes
Joomla! Intern
Joomla! Intern
Posts: 94
Joined: Thu Sep 15, 2005 7:30 am

[FIXED] Unable to call specific controller

Post by adam.hughes » Thu Jan 15, 2015 5:03 pm

I'm currently trying to recode my Joomla 2.5 application to work inside Joomla 3.3.
This is a very simple admin only component.
Reading all the documentation I could find on Joomla 3.3 coding standards I see that you should have a separate controller for each view, so keeping inline with this I'm trying to call a specific controller, but everytime I do my base controller.php file is called.

For example I have the following url in my component :
/administrator/index.php?option=com_que ... sk=runtest

I was expecting the above url to call the controller called test (which would be filename controller/test.php).
Then it would run function runtest from that controller.
So it should open file controllers/test.php
Run the function runtest in the test.php controller
Then open the runtest view (file views/runtest/view.html.php (using layout default which is file views/runtest/tmpl/default.php))

What is actually happening is that my base controller (controller.php) is called and the display function inside the controller is called and the test view is displayed.

The code from my base file (questaudit.php) is listed below :

Code: Select all

defined( '_JEXEC' ) or die( 'Restricted access' ); 
	
	if (!JFactory::getUser()->authorise('core.manage', 'com_questaudit'))
	{
		return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
	}
	
	$controller  = JControllerLegacy::getInstance('Questaudit');
	$controller->execute(JFactory::getApplication()->input->get('task'));
	$controller->redirect();
The code from my base controller (controller.php) is

Code: Select all

defined('_JEXEC') or die;
   
   class QuestAuditController extends JControllerLegacy
   {
	   protected $default_view = 'questaudits';
	
	   function __construct()
	   {
		   parent::__construct();
		}
     
	   public function display($cachable = false, $urlparams = false)
	   {
		   require_once JPATH_COMPONENT.'/helpers/questaudit.php';
		
		   $view = $this->input->get('view', 'questaudits');
		   $layout = $this->input->get('layout', 'default');
		   $id = $this->input->getInt('id');
		   //die("View is {$view}, layout is {$layout} and id is {$id}");

		   parent::display($cachable);
		}
	}

adam.hughes
Joomla! Intern
Joomla! Intern
Posts: 94
Joined: Thu Sep 15, 2005 7:30 am

Re: [FIXED] Unable to call specific controller

Post by adam.hughes » Fri Jan 16, 2015 7:54 pm

I found my issue.
Joomla 3 (and 2.5) have two types of controllers.
The master controller (admin/controller.php) which is used whenever you are going to display a page.
Then you have subcontrollers for all tasks that do not require displaying anything (for example updating a database record). The subcontroller would be used to update the record, then it would pass the result back to the master controller which would then be used to display the page to the end user.

When you call the master controller you do so by making a call to a task as normal. For example :
option=com_questaudits&view=test&task=runtest
The above would use the master controller and run function runtest from inside the master controller and then display the results in the test view.

When you want to make a call to a subcontroller you just make a call to a task in the following format : CONTROLLER.FUNCTION
For example :
option=com_questaudits&view=test&task=testing.runtest
This would load teh subcontroller testing and run function runtest


Locked

Return to “Joomla! 3.x Coding”