The Joomla! Forum ™



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.



Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Sat Nov 26, 2011 6:45 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Sat Nov 26, 2011 6:24 pm
Posts: 2
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.


Top
 Profile  
 
PostPosted: Sat Nov 26, 2011 10:07 pm 
User avatar
Joomla! Master
Joomla! Master

Joined: Thu Aug 18, 2005 8:55 pm
Posts: 20048
Location: Nijmegen, The Netherlands
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 - Community Leadership Team
http://www.db8.nl - Joomla specialist, Nijmegen, Nederland
Joomla 2.5 multilanguage in 10 steps: http://www.db8.nl/en/joomla-presentatio ... ge-website


Top
 Profile  
 
PostPosted: Tue Nov 29, 2011 9:08 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Mar 10, 2011 9:27 pm
Posts: 26
Location: Bahamas to New England coastline
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


Top
 Profile  
 
PostPosted: Fri Dec 09, 2011 11:31 am 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Tue Nov 25, 2008 7:10 pm
Posts: 233
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


Top
 Profile  
 
PostPosted: Sun Dec 11, 2011 3:48 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Mar 10, 2011 9:27 pm
Posts: 26
Location: Bahamas to New England coastline
I have found a promising tutorial here: [url]http://docs.joomla.org/How_to_use_the_JToolBar_class_in_the_frontend
[/url]
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,
Quote:
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


Top
 Profile  
 
PostPosted: Mon Dec 12, 2011 12:29 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Mar 10, 2011 9:27 pm
Posts: 26
Location: Bahamas to New England coastline
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


Top
 Profile  
 
PostPosted: Mon Dec 12, 2011 1:49 am 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Tue Nov 25, 2008 7:10 pm
Posts: 233
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


Top
 Profile  
 
PostPosted: Fri Dec 16, 2011 6:55 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Mar 10, 2011 9:27 pm
Posts: 26
Location: Bahamas to New England coastline
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:
    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_JToolBar_class_in_the_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:
    <?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:
       <?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


Top
 Profile  
 
PostPosted: Tue Jan 03, 2012 11:23 pm 
User avatar
Joomla! Master
Joomla! Master

Joined: Thu Aug 18, 2005 8:55 pm
Posts: 20048
Location: Nijmegen, The Netherlands
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 viewtopic.php?f=626&t=672620

_________________
Kind Regards,
Peter Martin, Global Moderator - Community Leadership Team
http://www.db8.nl - Joomla specialist, Nijmegen, Nederland
Joomla 2.5 multilanguage in 10 steps: http://www.db8.nl/en/joomla-presentatio ... ge-website


Top
 Profile  
 
PostPosted: Wed Jan 04, 2012 9:55 am 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Tue Nov 25, 2008 7:10 pm
Posts: 233
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.

Top
 Profile  
 
PostPosted: Wed Jan 04, 2012 3:15 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Mar 10, 2011 9:27 pm
Posts: 26
Location: Bahamas to New England coastline
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 



Who is online

Users browsing this forum: No registered users and 24 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group