Using backend controller task and model in the frontend

50 views
Skip to first unread message

GhiaMar

unread,
Aug 1, 2022, 10:06:25 AM8/1/22
to Joomla! General Development
Hi! I've finished my messaging component in the backend, everything works as I want, can create messages, recipients, can send messages to recipients using AJAX to avoid PHP max execution time.

Now I want to create the frontend component and I wonder if I can use admin model files so I don't DRY. Because I need a user to be able to login in the frontend, then CRUD messages and send them to their assigned recipients and I really don't want to duplicate the task controller->send() (which does the send AJAX magic) and model->send() code.

Thanks in advise!

MarkRS

unread,
Aug 2, 2022, 5:22:04 AM8/2/22
to Joomla! General Development
Yes, it's possible to use the backend classes in the front end.  The problem with that sharing (which I've also hoped to do) is there are sometimes important differences in the base classes, at least that's the way it was in J3.

I think the way around this is to use helpers as much as possible.

GhiaMar

unread,
Aug 2, 2022, 8:26:21 AM8/2/22
to Joomla! General Development
Thanks! I've found some examples that use Factory::getApplication()->bootComponent('com_mycomponent')->getMVCFactory()->createModel(...) and ->createController(...) in the frontend, I assume that's the way to do it in J in the frontend, I only want to use some controlles/model logic for the send process so I don't DRY.

Thanks a lot!
Reply all
Reply to author
Forward
0 new messages