【问题标题】:invoke a view-method from a controller task joomla从控制器任务 joomla 调用视图方法
【发布时间】:2012-05-08 10:44:22
【问题描述】:

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

/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(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*/

  }
}

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

【问题讨论】:

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


    【解决方案1】:

    试试

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

    【讨论】:

      【解决方案2】:

      你可以试试把这个放到控制器的跳转函数中

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多