2

I am trying to create Joomla2.5 component via MVC. I want to direct controller to mydisplay() method defined in view.xml.php from task=jump in entry point. Thanks.

/ROOT/components/com_api/views/api/view.xml.php

<?php
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

/**
 * XML View class for the Api Component
 */
class ApiViewApi extends JView
{
// Overwriting JView display method

function mydisplay($tpl = null)
{
//echo JRequest::getVar('task');

    //$this->get('Ister');
    // Assign data to the view
    $this->msg = $this->get('xCredentials');

    // Check for errors.
    if (count($errors = $this->get('Errors')))
    {
        JError::raiseError(500, implode('<br />', $errors));
        return false;
    }

    // Display the view
    parent::display($tpl);
}



}
?>

ROOT/components/com_api/api.php(entry point controller)

<?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 Api
$controller = JController::getInstance('Api');


// Perform the Request task
$controller->execute(JRequest::getCmd('task'));

$controller->redirect();

?>

ROOT/components/com_api/controller.php(controller with task=jump)

<?php

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

// import Joomla controller library
jimport('joomla.application.component.controller');
/**
 * Api Component Controller
 */
class ApiController extends JController
{
function jump()
  {
    //parent::display();


/* invoke mydisplay method from view.xml.php, located in views*/

  }
}

How do i call mydisplay() method in view.xml.php after executing a task=jump?

tereško
  • 58,060
  • 25
  • 98
  • 150
nuthan
  • 465
  • 2
  • 5
  • 19

2 Answers2

2

Try

$view = $this->getView('Api', 'xml');
$view->setModel($this->getModel('Api'), true);
$view->display();
Valentin Despa
  • 40,712
  • 18
  • 80
  • 106
0

you can try put this in jump function of the controller

$view = $this->getView('API');
$view->mydisplay();
thanhtd
  • 391
  • 3
  • 10