Question

I am trying to register a custom task in my controller in Joomla 3.x so I am modifying the constructor (like in 1.5/2.5) with:

<?php
 // No direct access to this file
defined('_JEXEC') or die('Restricted access');

class jjemailControllerjjemail extends JControllerLegacy
 {
/**
 * constructor (registers additional tasks to methods)
 * @return void
 */
public function __construct($config = array())
{
    parent::__construct($config);

    // Register Extra tasks
    $this->registerTask('email, 'email');
}

public function email()
{
    $this->setRedirect('index.php?option=com_jjemail&view=thanks', $msg);
}
}

Now if I add a var dump in the constructor before the task registering then that is showing but adding a var dump into the email() function is giving nothing. So I guess I'm failing at registering the task somewhere.

The route calling this looking like: JRoute::_('index.php?option=com_jjemail&task=jjemail.email');

Anyone got any ideas as to why I'm failing in such stupid fashion?

Was it helpful?

Solution

As of Joomla 1.5 you don't need to register default tasks' names. You only register aliases to map them to one of controller's methods:

$this->registerTask('emailAbc, 'email');
$this->registerTask('unpublish, 'publish');

If you cannot stop execution of the app it would suggest you are calling wrong task from your form/link.

Check your form/link whether it contains a proper task like: option=com_jjemail?task=jjemail.email Joomla will do all job for you, mapping "jjemail.email" to the email method of your controller

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top