向自定义 Joomla 组件添加新视图 [英] Add a new view to a custom Joomla component

查看:27
本文介绍了向自定义 Joomla 组件添加新视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向我的自定义组件添加一个新视图.我遵循了这个 发布,但我不太清楚说明.

I'm trying to add a new view to my custom component. I've followed this post but the instructions are not quite clear to me.

这就是我所做的:

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

I copied the structure of my other view (called 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 实例:

I changed the billingdetails.php controller to be the same as plandetails.php but with billingdetails instance:

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:

I changed view.html.php in the billingsdetails folder with the appropriate class:

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

Now in my default.php (inside billingdetails view folder) I just echo "TESTING". If I go to the component with view name: mysite.com/index.php?option=com_plandetails&view=billingdetails

我收到此错误:

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

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

Note: I didn't make any changes to the model as I don't think that is necessary. I want to reuse the same methods for this view.

我还缺少什么?

推荐答案

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

Class name for the view should be the component's name, the word View, and then the view name. So the correct view class is like this:

class plandetailsViewBillingdetails extends JView

这篇关于向自定义 Joomla 组件添加新视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆