Add a new view to a custom Joomla component

2019-09-08 07:46发布

问题:

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.

This is what I did:

I copied the structure of my other view (called plandetails)

So now I have:

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

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();

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);
    }
}

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

I get this error:

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.

What else am I missing?

回答1:

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