1

I have just upgraded my site from Joomla 3.7 to 3.9 and I am getting errors related to my code for a component model class that extends an administrator component model class. The require_once line below was fine in Joomla 3.7. I replaced it with JLoader::import, but no luck.

Is the JPATH_COMPONENT_ADMINISTRATOR constant no longer valid in Joomla 3.9?

The error I'm getting is:

PHP Fatal error: Class 'NoDiceModelWidget' not found in C:\xampp\htdocs\nodice\components\com_nodice\models\widget.php on line 8

The import should be looking in C:\xampp\htdocs\nodice\administrator\components\com_nodice\models.

How can I import my administrator model to extend my front-end model?

<?php defined('_JEXEC') or die; //require_once JPATH_COMPONENT_ADMINISTRATOR.'/models/widget.php'; JLoader::import(JPATH_COMPONENT_ADMINISTRATOR.'/models/widget.php'); class NoDiceModelAuthorWidget extends NoDiceModelWidget { public function __construct($config = array()) { parent::__construct($config); } } 

1 Answer 1

2

JLoader::import() is generally meant for files that follow a certain naming convention. You can still use it as it will fall back to the specified filename, but you have to pass the basepath as the second argument:

JLoader::import('components.com_nodice.models.widget', JPATH_ADMINISTRATOR); 

Alternatively, you could use JLoader::register():

JLoader::register('NoDiceModelWidget', JPATH_ADMINISTRATOR . '/components/com_nodice/models/widget.php'); 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.