【问题标题】:Add a new view to a custom Joomla component向自定义 Joomla 组件添加新视图
【发布时间】:2013-10-01 17:06:26
【问题描述】:

我正在尝试向我的自定义组件添加一个新视图。我已经按照post 进行操作,但说明对我来说不是很清楚。

这就是我所做的:

我复制了另一个视图的结构(称为 plandetails)

所以现在我有:

site
controllers
helpers
language
models
views
controller.php
billingdetails.php //new controller
plandetails.php //previous controller
   plandetails //previous view
      tmpl
         default.php
         metadata.xml
      view.html.php
   billingdetails //new view
      tmpl
         default.php
      view.html.php

我将 billingdetails.php 控制器更改为与 plandetails.php 相同,但使用 billingdetails 实例:

defined('_JEXEC') or die;
// Include dependancies
jimport('joomla.application.component.controller');

// Execute the task.
$controller = JController::getInstance('Billingdetails');
$controller->execute(JFactory::getApplication()->input->get('task'));
$controller->redirect();

我用适当的类更改了 billingsdetails 文件夹中的 view.html.php:

class BillingdetailsViewBillingdetails extends JView
{
    // Overwriting JView display method
    function display($tpl = null) 
    {
        // Display the view
        parent::display($tpl);
    }
}

现在在我的 default.php(在 billingdetails 视图文件夹中)我只是回显“TESTING”。如果我转到具有视图名称的组件:mysite.com/index.php?option=com_plandetails&view=billingdetails

我收到此错误:

View not found [name, type, prefix]: billingdetails, html, plandetailsView

注意:我没有对模型进行任何更改,因为我认为没有必要。我想为这个视图重用相同的方法。

我还缺少什么?

【问题讨论】:

    标签: joomla joomla2.5


    【解决方案1】:

    视图的类名应该是组件的名称、单词View,然后是视图名称。所以正确的视图类是这样的:

    class plandetailsViewBillingdetails extends JView
    

    【讨论】:

      猜你喜欢
      • 2016-06-02
      • 2013-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      相关资源
      最近更新 更多