1

In my main controller, I'm successfully incorporating a custom path for the Model, but seem to be missing something for the custom path to the View.

The component path is:

\components
    \com_meetings
        \models
            \meetings
                meetings.php          (Joomla Default)
            \custom
                \meetings
                    meetings.php      (My custom override that works)
        \views
            \meetings                 (Joomla Default)
                \tmpl
                view.html.php          
            \custom                   (My Custom views Folder)
                \meetings             (Customized View)
                    \tmpl             (This folder is ignored)
                    view.html.php     (This DOES load)

So, with the below code, Joomla does properly load the custom Model but only partially loads the custom view. (My view.html.php is loaded, but the relevant \tmpl folder is ignored and it reverts back to the default \tmpl.

com_meetings\controller.php: (Joomla 3.6.2)

defined('_JEXEC') or die;
jimport('joomla.application.component.controller');
class MeetingsController extends JControllerLegacy {
    public function __construct($config = array()) {
        $this->input = JFactory::getApplication()->input;

        // Begin Custom Model and View Paths
        $view_name          = $this->input->getCmd('view', $this->default_view);
        // Custom Model Path
        $custom_model_path  = JPATH_COMPONENT.'/models/custom/';
        $custom_model       = $custom_model_path.$view_name.'.php';
        if(is_dir( $custom_model_path )){
            if(file_exists( $custom_model )){
                $config['model_path'] = $custom_model_path;
            }
        }
        // Custom View Path
        $custom_view_path   = JPATH_COMPONENT.'/views/custom/';
        if(is_dir( $custom_view_path )){
            $custom_view_path   .= $view_name;
            if(is_dir( $custom_view_path )){
                $custom_view        = $custom_view_path.'/view.html.php';
                if(file_exists( $custom_view )){
                    $config['view_path'] = JPATH_COMPONENT.'/views/custom';
                }
            }
        }
        // End Custom View Path

        parent::__construct($config);
    }

The above paths ARE considered in the __construct() method of libraries\fof\controller\controller.php around line 594 and 617, and does load my view.html.php, but as mentioned the relative \tmpl folder is being ignored.

Line 594   if (array_key_exists('model_path', $config))....
Line 617   if (array_key_exists('view_path', $config))

views\custom\meetings\view.html.php

class MeetingsViewMeetings extends JViewLegacy {
public function display($tpl = null)
{
    $app = JFactory::getApplication();
    if (count($errors = $this->get('Errors'))) {
        throw new Exception(implode("\n", $errors));
    }

    $this->_prepareDocument();
    \\ The override gets this far;
    parent::display($tpl);
}

I can't follow where this is being checked, and can't see what I've done wrong. Any suggestions are welcomed~

P.S., I know I can put override views in the template, but I want to implement the custom path of Joomla at the component level to retain the customizations regardless of what Template may be active.

ADDITONAL UPDATE When looking at the $view, I see that it has resolved the paths to check for. So I guess the question is how to get my custom path between these 2:

[_path:protected] => Array (
        [template] => Array (
                [0] => C:\www\commission\templates\protostar\html\com_meetings\meetings\
                [1] => C:\www\commission\components\com_meetings\views\meetings\tmpl\
            )
    )
[_template:protected] => C:\www\commission\components\com_meetings\views\meetings\tmpl\default.php
1

I think you need to path 'template_path' in the config as well. Probably something like

$config['template_path'] = array(
    JPATH_COMPONENT.'/views/tmpl',
    $custom_view_path.'/tmpl',
    /* maybe other override place here like the template */
); 

I don't think any of the autogenerated paths match your file structure (lines 2703 to 2725).

    if (!array_key_exists('template_path', $config))
    {
        $config['template_path'][] = $componentPaths['main'] . '/views/' . FOFInflector::pluralize($config['view']) . '/tmpl';

        if ($templateOverridePath)
        {
            $config['template_path'][] = $templateOverridePath . '/' . FOFInflector::pluralize($config['view']);
        }

        $config['template_path'][] = $componentPaths['main'] . '/views/' . FOFInflector::singularize($config['view']) . '/tmpl';

        if ($templateOverridePath)
        {
            $config['template_path'][] = $templateOverridePath . '/' . FOFInflector::singularize($config['view']);
        }

        $config['template_path'][] = $componentPaths['main'] . '/views/' . $config['view'] . '/tmpl';

        if ($templateOverridePath)
        {
            $config['template_path'][] = $templateOverridePath . '/' . $config['view'];
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.