2012-05-08 75 views
2

我想通過MVC創建Joomla2.5組件。我想直接將控制器從task = jump入口點的view.xml.php中定義的mydisplay()方法。謝謝。從控制器任務調用視圖方法joomla

/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 /組件/ 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(帶任務=跳轉的控制器)

<?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()方法?

回答

0

你可以試試把這個控制器的跳轉功能

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

嘗試

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