CRUD Features in frontend

This forum is for general questions about extensions for Joomla! 2.5.

Moderators: pe7er, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
mnifakram
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sat Nov 26, 2011 6:24 pm

CRUD Features in frontend

Post by mnifakram » Sat Nov 26, 2011 6:45 pm

Please can any body provide me an url or manual how to develop mvc component that have the new, edit,delete tasks in frontend (i'm developing a component to manage menus from front end) thanks in advance.

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 24929
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: CRUD Features in frontend

Post by pe7er » Sat Nov 26, 2011 10:07 pm

Welcome to Joomla forum!

The Joomla's default frontend components com_content and com_weblinks use some parts of CRUD (Create-Read-Update-Delete). Maybe you could analyse those?
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

User avatar
islandBilly
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Thu Mar 10, 2011 9:27 pm
Location: Bahamas to New England coastline

Re: CRUD Features in frontend

Post by islandBilly » Tue Nov 29, 2011 9:08 pm

Those components are so much more complicated than the com_helloworld one, I have been looking at them on and off for weeks! Could somebody please add onto the MVC model tutorial for 1.6 and show how you would get a form list and an edit page into the front end??

I am clearly not the only one who needs to do this.
"In theory, there's no difference between theory and practice; in practice, there is." - Yogi Berra

MatthewSchenker
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 233
Joined: Tue Nov 25, 2008 7:10 pm

Re: CRUD Features in frontend

Post by MatthewSchenker » Fri Dec 09, 2011 11:31 am

Hello,
I'd really like to know more about this as well.

What's the best way to directly access Joomla's core fields for CRUD operations?

Thanks,
Matthew

User avatar
islandBilly
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Thu Mar 10, 2011 9:27 pm
Location: Bahamas to New England coastline

Re: CRUD Features in frontend

Post by islandBilly » Sun Dec 11, 2011 3:48 pm

I have found a promising tutorial here: http://docs.joomla.org/How_to_use_the_J ... _frontend
It seems that the idea MAY be to create a form that has id="adminForm" and lists each of the rows you want to maintain. In the view that uses this form, you add a getToolBar method, and this provides buttons to invoke the CRUD functions.

But then the article says,
Also, and as explained above, you'll need to add functions within the controller that is called when one of the toolbar buttons is pressed, to process the request gracefully.
BUT it never did explain how to do this "above" or anyplace else. I think we're close here, but so far I have not managed to add whatever is needed to make this work.

Anybody else have any luck?

~~~~
Okay, turns out maybe the author meant "below" instead of "above", because below the 1.6 part is a longer 1.5 part, and it refers to some changes to the controller. A little experimenting shows that he means the main site controller. Now, it looks like you can put in methods that will cause the system to try to open a view when you hit a button, but then he says, "You can put any code in there you want". Well, thanks! It would be helpful for us lesser types to know just what code effin' Joomla would like to see for those various functions! There are so many hidden defaults of every kind that it's about impossible.

Maybe the Joomla team should be forced to take a year off and just thoroughly document what they've done so far?
"In theory, there's no difference between theory and practice; in practice, there is." - Yogi Berra

User avatar
islandBilly
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Thu Mar 10, 2011 9:27 pm
Location: Bahamas to New England coastline

Re: CRUD Features in frontend

Post by islandBilly » Mon Dec 12, 2011 12:29 am

Ok, I have gotten my user-set of database rows to come out in a site-side list; I have the toolbar buttons that try to add or edit or delete; now when I try an add, I get an improperly generated set of fields cuz I don't seem to be processing jform stuff; when I try to edit one of the rows, I get a 500 error and it says I am not authorized to edit. I don't want to try delete.

I still think there is way more going on under the covers, starting from that little ol' helloworld component in MVC tutorial.
"In theory, there's no difference between theory and practice; in practice, there is." - Yogi Berra

MatthewSchenker
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 233
Joined: Tue Nov 25, 2008 7:10 pm

Re: CRUD Features in frontend

Post by MatthewSchenker » Mon Dec 12, 2011 1:49 am

Hello,
There is most certainly is something "going on under the covers"! Getting simple CRUD operations to work in Joomla is obviously a tremendous challenge. But it really should be a fairly simple thing to do for any Web site.

All the CCKs you see in the JED are more or less trying to make CRUD work in Joomla. It's a huge challenge.

I'm trying to understand what's going on under the hood (or covers) that controls this.

Thanks,
Matthew

User avatar
islandBilly
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Thu Mar 10, 2011 9:27 pm
Location: Bahamas to New England coastline

Re: CRUD Features in frontend

Post by islandBilly » Fri Dec 16, 2011 6:55 pm

I have finally managed to accomplish this, full CRUD in the front end via my custom component, which also, of course, has full CRUD and more in the back end. The basic idea is to bring all those files from the admin side to the site side. It may seem needlessly redundant, but along the way, you can alter the models so that the users don't see all the data that the admin sees, change the layouts, etc.

Assuming you have developed your custom component from the MVC Tutorial, you should have a component that has a nicely functioning admin side, with its own categories that can be added and linked to the custom table's rows, and you have implemented ACL. What you have on the site side is a mostly useless ability to display a single record's data via a menu item, right? The goal then is to be able to create a menu item that puts out a list of data rows that the user can then do CRUD with. So starting at the site entry point and working through the structure,
  • site/<comName>.php should need no changes.
    • Let me clarify my syntax here and say that when I write '<comname>' I mean for you to substitute your component name as all lower case, eg 'helloworld'; when I write '<ComName>' I mean for you to substitute your component name as a class name, eg HelloWorld; and when I say something like '<comname>s' I mean for you to substitute the component name and add an 's' onto it.
  • site/controller.php needs to change its display method overwrite so that it sets the default view to the one that ends in an 's':

    Code: Select all

    JRequest::setVar('view', JRequest::getCmd('view', '<ComName>s'));
    In the admin version, there is also a submenu being added, but for the site side I did not allow categories to be maintained so I had no need for a sub-menu. If you want one, then add that method to the controller file too. You would also need to add the helpers folder and file from the admin side. Frankly I am not sure it will work without a jimport of JSubMenuHelper, and don't know if that can be done.
  • Now that you are going to have two views and two models, you need two sub-controllers, as on the admin side. So add a controllers folder under the site folder, with the same two sub-controller php files as in admin.
  • In the site/views folder add a <comname>s folder. That folder will contain a view.html.php file that is more like the one in admin/<comname> than the one in admin/<comname>s. This is the view that will be called by the site-level controller now that we have changed it. As described in http://docs.joomla.org/How_to_use_the_J ... e_frontend, the getToolBar method is defined in the view file and must use JToolBar and not JToolBarHelper. BUT you must call the getToolBar method in the layout, NOT in the view file. For unknown reasons, it does not work there (which is where it works fine on the admin side).
  • In this <comname>s folder you also add a folder named 'tmpl', again very similar to the one by that name on the admin side. The so-called layout file goes in here, named default.php. You can break it down into head body and foot files as the MVC tutorial coded it in the admin side, or just code your layout all in this file, as you wish. But it is in this layout that you place the call to getToolBar, so that the buttons come out where you want them.
  • Also in this tmpl folder you must put a default.xml file. This file needs only the layout tag under metadata like this:

    Code: Select all

    <?xml version="1.0" encoding="utf-8"?>
    <metadata>
    	<!-- the layout element is what creates a menu item to choose in menu manager 
    	   this one is still simple because there is only one choice: the user's data
    	-->
    	<layout title="COM_<COMNAME>_LIST_MENU_ITEM_TITLE">
    		<message>COM_<COMNAME>_LIST_MENU_ITEM_DESC</message>
    	</layout>
    </metadata>
    This is all you need in order to create a menu item choice in the back end for the list.
  • In the lifecalendar/tmpl folder put a copy of the edit.php like the one on the admin side. Because of context, it will generate its form from the fieldset defined in site/models/forms/lifecalendar.xml - you might give the fieldset a different name from the one in admin just to make that more clear. Note: in the site model I am restricting the database retrieval to the user's data only, and I store the user's id in a column named 'userid' in my custom table for that purpose. So the xml in site/model/forms differs from the admin one by having the field named 'userid' be type=hidden. I have found no way to express the default userid value in the xml file, so I had to code a replacement input tag in edit.php for userid conditioning in the foreach loop. My foreach loop now looks like this:
    



    Code: Select all

       <?php foreach($this->form->getFieldset('details') as $field): ?>
    			<?php if (!$field->hidden): ?>
    				<?php echo $field->label; ?>
    			<?php endif; ?>
    			<?php if ($field->name == 'jform[userid]') {
    				echo '<input type="hidden" name="jform[userid]" id="jform_userid" value="' . JFactory::getUser()->id . '" />';
    			     } else { echo $field->input; } ?>
    		     <?php endforeach; ?>
    In this way, it looks like it was generated by the jform process and gets passed on.
  • On the site side, I did not create a Table object to encapsulate my table because I am a afraid that it will automatically load the entire table. In my case that table is going to be quite large. Not using the table object seems to have deprived me of being able to do the changable sort columns, but I didn't get that working well on the admin side anyway.
  • For the models folder on the site side, you need the very same structure of folders and files as on the admin side. The differences are in the content. The forms folder contains the <comname>.xml file and the <comname>.js file that is used to generate the edit form and client-side validation script. As I said above, you can alter the fieldset in here to reflect differences from the admin side, but you cannot leave out any field that needs to be given a value in the database table. The models/<comname>.php file extends JModelAdmin and should be identical to its admin side counterpart. The models/<comname>s.php file extends JmodelList, and its getListQuery method will probably be a little different from its admin counterpart, depending on your needs. Unlike the other model methods, this one is not directly called in the view - that happens in the background when the list page is generated - so don't get fancy and change its name.
Now you should have all the pieces so that you can add a menu item to whatever menu you want in your site, and when you go there, you should see the list of items from your component with checkboxes to select and then maintain. But a non-admin user will probably be told he does not have permission to add or change or delete. You overcome this by going to the Components drop-down in the Adminstration Area, ie the back end, then find your component and select it. If you added categories from when you went through the MVC tutorial, you will have a categories tab in your component manager window. Select the categories and then for each one, you can select it, hit Options, and set the level of permissions you desire. If you have implemented record-level ACL, you can do this in the other tab of your component manager, for each record. Thus you have total Joomla-style overkill permission control. Enjoy!
"In theory, there's no difference between theory and practice; in practice, there is." - Yogi Berra

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 24929
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: CRUD Features in frontend

Post by pe7er » Tue Jan 03, 2012 11:23 pm

Thanks for your informative post!
At the moment I am developing a Joomla 1.7 component.
The back-end, with use of the JForm feature, was not very difficult.

However, now I have some problems with the front-end as well.
E.g. how to implement CRUD, how to use multiple subcontrollers in 1.7, and how to implement JForm at the front-end (if possible).

FYI: I found some other interesting forum topic about it:
JForm on the front-end http://forum.joomla.org/viewtopic.php?f=626&t=672620
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

MatthewSchenker
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 233
Joined: Tue Nov 25, 2008 7:10 pm

Re: CRUD Features in frontend

Post by MatthewSchenker » Wed Jan 04, 2012 9:55 am

Greetings islandBilly,
Thanks for the great effort putting those instructions together. I see what you're trying to do, and it is going in the right direction!

However, it sort of shows just how difficult it is to make Joomla do this kind of thing. It's almost as if Joomla doesn't want to allow CRUD/custom fields. You have to force it and twist it to make it cooperate. And even after all that work, there are still some things it's not doing.

My dream is to be able to do the following:
1. Start with Joomla's "native" form builder, or use a Joomla form extension
2. Create fields and forms as entry points for data
3. Reference submissions (fields) with tags, like the {module_position} concept, inside layouts (articles)
4. Keep track who submitted forms (articles)
5. Assign create, read, update, and destroy rights to articles

Although this seems like a lot to ask, there are various applications in the Joomla universe that do pieces of this. Just some examples of extensions that are accomplishing at least a part of what we're talking about here:
- I use RSForm for a lot of my sites. It makes it very easy to create data, keeps track of who submitted the data, and lets users review submissions based on access rights. But you can't update or destroy submissions based on users.
- Joomla has a powerful form builder, but it's not at all easy to build entry forms with it and keep track of who submitted it.
- DB Replacer by NoNumber lets you find and update or destroy database entries. But I don't know how to apply it based on user, or how to connect its actions to forms.

There are others I could name here. The point is, the building blocks are there. But they are kind of spread out and separated. I wonder if there's some solution that could involve putting together the capabilities of various extensions?

Thanks,
Matthew
Last edited by MatthewSchenker on Wed Jan 04, 2012 3:50 pm, edited 4 times in total.

User avatar
islandBilly
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Thu Mar 10, 2011 9:27 pm
Location: Bahamas to New England coastline

Re: CRUD Features in frontend

Post by islandBilly » Wed Jan 04, 2012 3:15 pm

Thanks, Matthew,

You are absolutely right about how all those cool building blocks are spread out in various core components and extensions, and indeed my main goal was to bring it all together in one component.

I'm guessing that the reason Joomla makes this so difficult is their most basic conceptualization is that the admin side does the data maintenance and the site side is just for people to enjoy looking at. I have never looked at their fruit store sample to see how customers enter orders, but there might be something in there we can use too.
"In theory, there's no difference between theory and practice; in practice, there is." - Yogi Berra

bwls
Joomla! Intern
Joomla! Intern
Posts: 61
Joined: Mon Oct 04, 2010 7:56 pm
Location: Wheeling, IL
Contact:

Re: CRUD Features in frontend

Post by bwls » Thu May 14, 2015 7:09 pm

Any plans on packaging this up and selling it?


Locked

Return to “Extensions for Joomla! 2.5”