class MyController extends JControllerLegacy { public function display($cachable = false, $urlparams = false) { // Code to fetch data from model $data = $this->getModel('MyModel')->getData(); // Code to pass data to the view $this->view = $this->getView('MyView', 'html'); $this->view->setData($data); $this->view->display(); } }
class MyController extends JControllerLegacy { public function save() { // Code to validate user input and save to database $input = JFactory::getApplication()->input; $data = $input->get('data', array(), 'array'); $model = $this->getModel('MyModel'); $model->validate($data); $model->save($data); // Code to redirect to a success message $this->setRedirect(JRoute::_('index.php?option=com_mycomponent&view=myview&task=display'), JText::_('COM_MYCOMPONENT_SAVE_SUCCESS')); } }This example shows how to create a controller action that handles user input, validates it, and saves it to a database. It also redirects the user to a success message. The JControllerLegacy class is part of the Joomla Framework's MVC package library.