I have my own library file that extends the core joomla file.
for example:
class RmkModelForm extends JModelAdmin
however, it is not working when porting the component to J4
So far this is the last item. However it could be hiding further problems, wont know until I get there :)
Here is the backtrace
Call stack
1 () JROOT/libraries/src/MVC/Controller/BaseController.php:586
2 Joomla\CMS\MVC\Controller\BaseController->createModel() JROOT/libraries/src/MVC/Controller/BaseController.php:760
3 Joomla\CMS\MVC\Controller\BaseController->getModel() JROOT/libraries/src/MVC/Controller/FormController.php:446
4 Joomla\CMS\MVC\Controller\FormController->getModel() JROOT/libraries/rmk/controller/form.php:227
5 RmkControllerForm->getModel() JROOT/libraries/rmk/controller/form.php:314
6 RmkControllerForm->edit() JROOT/libraries/src/MVC/Controller/BaseController.php:734
7 Joomla\CMS\MVC\Controller\BaseController->execute() JROOT/administrator/components/com_registrationmanagerking/registrationmanagerking.php:133
8 require_once() JROOT/libraries/src/Dispatcher/LegacyComponentDispatcher.php:69
9 Joomla\CMS\Dispatcher\LegacyComponentDispatcher::Joomla\CMS\Dispatcher{closure}() JROOT/libraries/src/Dispatcher/LegacyComponentDispatcher.php:71
10 Joomla\CMS\Dispatcher\LegacyComponentDispatcher->dispatch() JROOT/libraries/src/Component/ComponentHelper.php:380
11 Joomla\CMS\Component\ComponentHelper::renderComponent() JROOT/libraries/src/Application/AdministratorApplication.php:116
12 Joomla\CMS\Application\AdministratorApplication->dispatch() JROOT/libraries/src/Application/AdministratorApplication.php:159
13 Joomla\CMS\Application\AdministratorApplication->doExecute() JROOT/libraries/src/Application/CMSApplication.php:233
14 Joomla\CMS\Application\CMSApplication->execute() JROOT/administrator/includes/app.php:63
15 require_once() JROOT/administrator/index.php:36
Labels |
Added:
?
|
Does anyone know if extending Joomla classes is still possible?
I have my own library that extends core code a bit, but I'm getting an error.
Call to a member function createModel() on null
in my library, I do this:
class RmkControllerForm extends JControllerForm{
and in my components controller, I am doing this:
$controller = JControllerLegacy::getInstance('Registrationmanagerking');
$controller->execute($input->getCmd('task', ''));
its the execute command that triggers the error.
Just re-read your issue, what is calling createModel? Since this is where your error is, yet you haven’t shown the code for calling it? And the code leading up to calling it.
Try to look at core extensions that have been migrated to get an idea
I am trying to attach source code files. but it wont let me.
php file, wrong file type.
txt file tells me to select an editor
How can I attach the source code?
Try to zip the file before uploading, it should work, maybe you should provide your full library (or full package of your extension), it would help checking the issue easier
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-12-22 05:59:06 |
Closed_By | ⇒ | rgjoyce |
This is the controller from my component that uses the library
admin_event.zip
Quick look at the code, it happens because your RmkControllerForm class does not extends JControllerForm properly. Instead of calling parent::__construct before adding custom logic to the class, you write all the code of constructor from JControllerLegacy and JControllerForm to contructor method of your own class, thus custom logic added to Joomla 4 to controller is not available for using on your class
With this specific error, it happens because factory is not initialized https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/MVC/Controller/BaseController.php#L482 . To fix this, you will need to implement code in your own controller form class properly
afraid you lost me.
This has been working fine in Joomla 3.4+ including 3.9 for months.
Something must have changed severely for this to break.
I notice that this code you have pointed to says LegacyFactory.
Does that mean that in J5 this will need changing again?
When you extend a class, typically you should call the parent constructor to make sure the class is still set up correctly:
public function __construct()
{
parent::__construct()
// do stuff
}
From what @joomdonation says you aren't doing that, rather you copied in all of the parent constructor logic to your class. This isn't a viable solution.
The constructor for the base controller in Joomla 4 has a bunch of new logic that isn't being executed because your controller isn't setting things up correctly.
thanks.I missed that I'd not added the constructor to that class.
My Bad
More info:
$controller = JControllerLegacy::getInstance('Registrationmanagerking');
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/23309.