Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 1500

Joomla! 5.x Coding • Right/best way to implement CRUD on frontend?

$
0
0
Thanks for reading this, hope you can help me figure out what I'm doing wrong...

I'm trying to create a component showing a front-end list of items and options to create/edit/delete list items.
For the create/edit/delete functions I use the backend toolbar on the frontend.
I am using https://www.techfry.com/resources/how-t ... -component for inspiration.
I want to implement this functionality using Joomla 5 behavior where available, being future-proof for Joomla 6 where possible.

My problem is multi-level:
First problem occurs when I use the code in attached com_stars (fails).zip I get an exception when trying to create an item using the 'new' option. in PlanetModel.php my loadFormData() uses getItem() from Joomla AdminModel which returns false, and this causes the exception later on creating the view.
So problem 1 is why getItem() returns false, not an empty "template" array?
My first work-around/solution is have my loadFormData() return an empty array: Yes! Exception is gone, I get the form view allowing me to enter data.

Then I run into my second problem, which occurs when I try to save the record: in save() in PlanetModel.php I see the data array has id=1. This should be 0 to create a new record.
The id in the saved from is 0, so how come the id=1?
With my second work-around I override getRedirectToItemAppend() in PlanetController.php to add &id=0 when called without parameters as happens in the add() function in the parent Joomla FormController.php.

So where do I go wrong? How do I implement CRUD on my list, without exceptions when calling ?view=planet&layout=edit without having to override getRedirectToItemAppend() ?

Thanks for your pointers, suggestions, ideas, so I can use Joomla as it is meant to be!

Statistics: Posted by kurantje — Mon Aug 05, 2024 7:26 am



Viewing all articles
Browse latest Browse all 1500

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>