从控制器任务joomla调用视图方法

时间:2012-05-08 10:44:23

标签: php joomla joomla2.5 joomla-component joomla-task

我正在尝试通过MVC创建Joomla2.5组件。我想将控制器指向view.xml.php中定义的mydisplay()方法,该方法来自入口点的task = jump。感谢。

/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(入口点控制器)

<?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(带有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*/

  }
}

如何在执行task = jump后调用view.xml.php中的mydisplay()方法?

2 个答案:

答案 0 :(得分:2)

尝试

$view = $this->getView('Api', 'xml');
$view->setModel($this->getModel('Api'), true);
$view->display();

答案 1 :(得分:0)

你可以尝试把它放在控制器的跳转功能中

$view = $this->getView('API');
$view->mydisplay();