我正在尝试通过MVC创建Joomla2.5组件。我想将控制器定向到视图中定义的 mydisplay() 方法.xml.php从 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);
}
}
?>
根/组件/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();
?>
根/组件/com_api/控制器.php(带任务=跳转的控制器)
<?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*/
}
}
如何在视图中调用 mydisplay() 方法.xml.php 执行任务=跳转后?
尝试
$view = $this->getView('Api', 'xml');
$view->setModel($this->getModel('Api'), true);
$view->display();
你可以尝试把它放在控制器的跳转函数中
$view = $this->getView('API');
$view->mydisplay();