|Tutorial problem: Developing MVC Component for Joomla!2.5||TDZWeb||8/6/12 1:47 PM|
I have done this tutorial up to part 14: http://docs.joomla.org/Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_14
Adding ACL to the Helloworld view fails because the class HelloWorldViewHelloWorld (extends JView) does not have the method 'canDo' defined. The application exits when trying to add or edit a message and gives an undefined method notice and then fatal undefined property of that method as the view calls the get method: 'if ($this->canDo->get('core.admin')):' and so on ( in the admin/views/tmpl/edit.php file, line 59)
The tutorial is massive compared to my skill level so I have no idea where the class acquires this method. I think it it supposed to pick it up automagically, but I pretty much feel like I am stumbling around in the dark at the moment. While this is certainly one way to learn, I would prefer if someone in the know took a look.
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Neil||8/6/12 1:56 PM|
Hang in there! Follow the entire tutorial before trying out the little tid bit.
There is a section in there, where you add a function to your helper. This function is what retrieves the actions you "canDo".
ACL takes a little bit to wrap your head around.
There are a lot of different parts. Which have to come together.
NeilSent from my iPhone
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/6/12 10:19 PM|
Apologies: when I look at the code you are right: $this->canDo should be a property of the HelloWorldViewHelloWorld-view in admin/views/helloworld/view.html.php which is not the case! For $canDo now only is a local variable in the addToolBar()-method in that class: $canDo = HelloWorldHelper::getActions($this->item->id);. If you want to use that in the template too, then you'll have to assign that variable as a property to that view-class: $this->canDo = $canDo;. It is wrong in the tutorial (probably the use in the template-file is added later) and I'll correct it.
Some remarks about adding that variable:
So, thank you for reporting this bug in the example-code and keep up your courage: if you made it 'till nr. 14, you've accomplished quite a lot.
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/6/12 10:37 PM|
Added to the Wiki: $this->canDo = $canDo; //for later use in the edit-form in the addToolBar()-method of that singular view. So now it should work. See remarks above however for more torough solutions. Also: the plural-view (HelloWorlds) is left unchanged.
Some days ago there also was a question about assigning properties to a view-class (what we used to do with AssignRef() for PHP4-compatibility). I'll walk through the tutorial to make it more in line with the preferred Joomla! coding style: declaring variables etc.
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||TDZWeb||8/7/12 12:11 AM|
Thank you very much! I must admit the MVC component looks daunting so to have a working Helloworld template will be invaluable to me.
If you are cleaning up you might notice some deprecated raiseErrors and I am curious about how you replace them. Personally I was just going to use PHP trigger_error instead of throwing exceptions "manually".
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/7/12 12:49 AM|
On Tuesday, 7 August 2012 09:11:24 UTC+2, TDZWeb wrote:
Yep, deprecated stuff like JError should be removed from the examples. The tutorial should not show old habits that you have to get rid of later...
JError was used for both logging errors and stopping execution of the program. You now should use JLog for logging and plain PHP for stopping the program or retrieving what has gone wrong. The rest of the story is the transition between the old way and the new one, but that should not be of any concern for this series of tutorials, I think.
BTW: if you have any suggestions of where to change the tutoprial, they are very welcome. You have just been playing around with it, so I bet you came across several things others would overlook. It is also very easy to contribute to the Wiki: just create an account (top right) and go ahead.
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||TDZWeb||8/8/12 9:35 AM|
This still did not work. The error is gone (canDo does now exist), but the access rules for the individual message does not appear (also the translation string for the rules pane is missing). With a little debugging I traced the problem back to the HelloWorldTableHelloWorld::bind function. The rules are never bound it seems. I don't know why. Could be a problem with the model or the way assets are handled. Given my limited knowledge it will take quite a bit of time for me to solve this puzzle.
On a side note, it was not possible to edit or delete categories. I fixed this by adding the following section to the admin/access.xml file (I peeked at com_contacts).
At least now all the functions of the component itself seems to work. I can add, edit and delete all the parts.
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/8/12 9:51 AM|
Mmm, sorry; what a mess. I'll put up a site and a github-repository with a working demo of all the stages of this tutorial. For this is counterproductive. Thanx anyway for digging in this so far. You probably learned a lot from that... I'll keep you informed via this list and we'll get there.
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/8/12 10:32 AM|
Did you give the right rights to the user in the backend? For (as you probably understand but to be clear about it) the lines you see in access.xml are not the rights themselves, but only give the possibility to couple rights for certain actions on certain assets to usergroups. After that the rights still have to be set. Will mention that in the tutorial too.
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||TDZWeb||8/8/12 10:36 AM|
Yeah I am logged in as Superuser. I checked now to be sure and I have all rights to the component. The rghts themselves does not seem to be a problem. As I said I can add, edit and delete messages and categories now. The bugs now seems to be more of a cosmetic nature.
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/8/12 10:54 AM|
Did you have to reinstall after you reworked the component? For I thought those access-rules are written to the database only once on installation (not sure). Just a detail.
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||TDZWeb||8/8/12 11:43 AM|
I uninstall and reinstall every time I encounter a problem. I have not tried to start from a new joomla install yet, but I just checked after an uninstall that the helloworld table and both the categories and assets gets wiped so every reinstall should be a clean slate.
I think right now I have a functionally working component, but the access rules for the individual messages do not display. Maybe its just a glitch in the the tmpl/edit.php template.
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/8/12 12:26 PM|
Are you (even as superuser) part of the "Special" Viewing Access Level?
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||TDZWeb||8/8/12 12:42 PM|
Yes, the joomla install is a pretty clean 2.5.6 install. I have only installed a language (Norwegian, nb_NO) and of course HelloWorld (over and over). Just so we are clear. The actual access levels seem to work, they only do not display in the edit view:
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||TDZWeb||8/8/12 3:27 PM|
I figured it out. In admin/views/helloworld/tmpl/edit.php, the problem was that there was no 'rules' field in the form referenced by the lines:
I added the following field to the admin/models/forms/helloworld.xml (this time by peeking at com_content's article MVC):
Right now it seems like I have a complete working helloworld component. I have not done the update server thing, but will play around a little bit with it. Maybe later this week I will set up versioning in eclipse and see if I cant make a tag for each step and then see if I can go through the steps just using the update server functionality.
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||elin||8/8/12 6:37 PM|
As has been discussed recently on a number of lists there is currently a real problem any time you attempt to use ACL without using com_categories as an intermediary between the component items and the component itself. The cascade
works exactly as expected just by having asset_id, making sure you extend jaccess properly to do your naming it will all work fantastically ... it's really easy. However if you miss any of those steps things get more complex. There has been a merge to the platform to fix some of this and make it work correctly in the absence of categories but i don't think it is in the current 2.5.
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||TDZWeb||8/8/12 9:28 PM|
Are you saying the #_helloworld table is incomplete? There is no asset_id (or access for that mater) column in the table.
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/9/12 1:07 PM|
On Thursday, 9 August 2012 06:28:54 UTC+2, TDZWeb wrote:Are you saying the #_helloworld table is incomplete? There is no asset_id (or access for that mater) column in the table.
No, I don't think the asset_id is necessary to control the rights on an item: the item is identified by the id in the #_helloworld-table. But it could be that that is not working well in case we would not have used categories. I think we just have to play around a bit more with this ACL and then add some practical hints and recipes to this Wiki-article how to use it in your own component. That is to say; how to use it at this moment in the CMS. For the whole ACL could change quite a bit in the future, I guess. But as Joomla! 2.5 is to stay around for a while (without big API-changes, so with the current ACL) it will be good to have some practical and working examples and best practices in the Wiki.
The code in this Wiki-article nr. 14 is mainly copied from the code in com_content and it looks like it has not been thoroughly tested in a working example component. Often developers start taking a core-component and add some fields.
For more info about the discussion Elin is referring to, see a.o.: https://groups.google.com/forum/?fromgroups#!topic/joomla-dev-platform/1IZPG3Vfyvc
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/9/12 1:10 PM|
Great! This is a good contribution to use to improve the Wiki-information. Thank you!
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Neil||8/9/12 1:12 PM|
I am sorry asset_id is necessary if you wish to implement item level ACL.
I like the idea of recipies on wiki of how to add ACL to your component. I still fumbling around with it since I don't wish to use categories. There are rid bits of information scattered everywhere. Wiki has the most information, when I finish my component and understand it, I will try to write up a wiki on it.
--You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/aysez86P4nQJ.
Sent from Gmail Mobile
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/9/12 1:22 PM|
On Thursday, 9 August 2012 22:12:15 UTC+2, Neil wrote:I am sorry asset_id is necessary if you wish to implement item level ACL.
Interesting. But where is it used in JAccess?
I'll play around a bit with this to see if I can show you a working example without an asset_id. If that is not possible, then indeed the asset_id is necessary (and is it me who will say "sorry").
I'm very interested in your code too.
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||TDZWeb||8/9/12 1:33 PM|
I just added an asset_id column to the #_helloworld table, reinstalled and the system started using it by itself once you start changing and adding things. I imagine using a direct lookup via asset_id will have performance benefits over manually constructing the unique asset names.
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||elin||8/9/12 6:17 PM|
The need for asset_id is pretty well documented in general, it is the key element of acl.
If you don't want to use categories you need to apply the patch for JAccess that has been applied to the platform and you could also read the related items on the platform list and this list.
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/9/12 11:14 PM|
I'll add the asset_id column to the wiki too.
Sorry, I thought it was only there for performance benefits. Still not clear to me if it also worked without the asset_id (and have the unique asset names manually constructed). I'll still play around with that to get that crystal clear. Will report that here.
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/9/12 11:18 PM|
On Friday, 10 August 2012 03:17:30 UTC+2, elin wrote:The need for asset_id is pretty well documented in general, it is the key element of acl.
Thanks. Will add something about it to this Wiki-page. Links to that documentation is welcome, however; maybe I overlooked something.
OK, I will also make a summary of that on this Wiki-page.
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||elin||8/10/12 6:13 AM|
You can have a unique name as in the extensions table but if you do that you can't inherit in a straighforward name, you need to use something like com_categories to set up the inheritance. All inheritance happens via the nested sets in the assets table.
On Friday, August 10, 2012 2:14:24 AM UTC-4, Herman Peeren wrote:
I'll add the asset_id column to the wiki too.
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||TDZWeb||8/10/12 11:22 AM|
Maybe this is a stupid question. If we have the asset_id in the components own table(s) and assuming the asset parent_id is correct, do we need the AssetName at all?
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/10/12 1:05 PM|
Of course it is not a stupid question: we should pose all kinds of questions like that to get everything totally clear in the end. I 'd like to understand it completely and explain it clearly in the Wiki. Still playing around with these per item ACL settings. Unfortunately have to stop now, grrrr... to be continued (but not tomorrow). Does everything in your HelloWorld-code work as expected now? I mean: setting, saving and displaying of per item rights.
Got a whole list of additions to the code in this Wiki-article now.
BTW: found this which also gives a recipe what to do to get this example working: https://www.joomlajingle.com/blog/39-joomla-acl-for-developers
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||elin||8/11/12 4:03 AM|
If you mean asset name in the asset table yes you do need a name of some kind. JAccess will automatically make it #__tablename.key but really I think you want something nicer looking. You should just pick a name for what an individual item is called.
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||TDZWeb||8/11/12 5:18 AM|
I made a test user and tried with different access groups and it appears to be working. I have not tried every possible combination of rules and access groups. In the end he changes that I have made are:
I think that pretty much covers it, but I have not made a tag for every step by going back and forth a little and debugging I must admit I may have lost track of all the modifications I made. I would have to start from scratch to be certain.
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||elin||8/11/12 6:14 AM|
Thanks Herman! That tutorial is really turning into a great collaborative document.
On Monday, August 6, 2012 4:47:48 PM UTC-4, TDZWeb wrote:
I have done this tutorial up to part 14: http://docs.joomla.org/Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_14
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/11/12 12:08 PM|
Thanks Ståle (is that your first name?)!. I also have the binding in the JTable and the missing of the ACL-part in the edit-layout in the downloadable zip. Plus some minor things like the missing language strings and missing parameters in _getAssetParentId(). And of course we'll still have to elaborate on the story of parent_ids and put some best practices for J! 2.5 online. Will edit the text in the Wiki and after that also in the downloadable zip (for which there is also a second reference with a 404).
// Bind the rules.
if (isset($array['rules']) && is_array($array['rules']))
$rules = new JAccessRules($array['rules']);
Parameters of _getAssetParentId: $table = null, $id = null
otherwise those variables are unknown in return parent::_getAssetParentId($table, $id);
Language strings in \admin\language\en-GB\en-GB.com_helloworld.ini:
COM_HELLOWORLD_ACCESS_DELETE_DESC="Is this group allowed to edit this message?"
COM_HELLOWORLD_ACCESS_DELETE_DESC="Is this group allowed to delete this message?"
In Adrian Rosian's text on joomlajingle.com he also uses a hidden var "asset_id" in the edit-layout. Will investigate the necessity and rationale of that.
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Neil||8/11/12 12:12 PM|
Hey Herman / Elin,
Elin I have found your posts and insight to extremely helpful. Thank you for that.
Herman I am going to have sometime next weekend if you want to compare notes. We can set up a time and meet up on Skype.
Sent from Gmail Mobile
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||TDZWeb||8/11/12 12:19 PM|
Yes thank you both Elin and Herman, a nice crash course in ACL this thread! And yes my first name is Ståle (Norwegian). I tend to go with nicknames/usernames on forums in general as a force of habit. It is hard to find the line between prudence and paranoia these days :p
|Re: Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/11/12 12:41 PM|
On Saturday, 11 August 2012 15:14:24 UTC+2, elin wrote:Thanks to evereybody working on this. It is fun how everybody brings in a piece of the puzzle to finally understand Joomla!'s 2.5 ACL completely.Thanks Herman! That tutorial is really turning into a great collaborative document.
Some of my misunderstanding is because I didn't use much of the functionallity for ACL built in into JTable. Will have a look whether I can use some of that functionallity also when using Doctrine ORM instead of JTable (one of the things I'm still exploring).
Elin, you twice mentioned extending JAccess in your postings, but that probably referred to JTable-extensions. Joomla!'s ACL is not only in JAcess (and JAccessRule + JAccessRules), but also in JUser and JTable. And it is in your JTable-extensions that you have to override some methods.
I'm working on a wiki-article that explains the working of the core classes involved in ACL.
Another Wiki-article about using item-level ACL:
Will put references in the footer of "our" ACL-article.
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/11/12 12:45 PM|
I go for: prudent paranoia. ;-)
Although I don't see any reason for paranoia when using your real name on a serious mailinglist.
How do you pronounce your name? For we don't have a å in our alphabeth...
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/11/12 12:53 PM|
On Saturday, 11 August 2012 21:12:57 UTC+2, Neil wrote:
Yes, great! I plan to have updated the text of this article (and the downloadable code) by then and also to have finished a wiki-article about the working of the various parts of the ACL (on the code level).I'm still figuring out the exact working of some parts and why things are done as they are. Looking forward meeting you.
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/11/12 12:56 PM|
We can also once do a Skype chat or maybe a Google+ hangout with more people about the subject.
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/12/12 1:00 AM|
On Saturday, 11 August 2012 21:45:47 UTC+2, Herman Peeren wrote:How do you pronounce your name? For we don't have a å in our alphabeth...
Sorry, will stay on topic and ask personal questions off-list. Further: lots of answers can be found on the web, so I better look it up before asking. E.g.: http://www.forvo.com/word/%C3%A5/
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||TDZWeb||8/12/12 8:57 AM|
hehe np, was going to answer its pronounced like "awe". I am not in favour of always answering "google it". Didn't know about that site though. Interesting to hear the nuances between the Scandinavian languages. Good find.
Back on topic: I don't quite understand the role of categories in all this. I don't suppose anyone could explain to me exactly why the com_helloworld would fail without it?
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/12/12 10:14 AM|
On Sunday, 12 August 2012 17:57:43 UTC+2, TDZWeb wrote:
That will be clear this week, I promise! At the moment I'm first updating the Wiki with all the changes we had (still busy with it). I also got access to the original zip on joomlacode.org, so I'll get that corrected too. And I'm still investigating everything around the working of JAccess and the relevant methods in JUser and especially JTable. I'll report it in a Wiki-article. I'm sure that it will be crystal clear then what the thing with those categories is.
It has something to do with setting the parent of the asset in the original _getAssetParentId() method of JTable: that always returns 1 (root-asset). If you have no categories, then the parent of the items should be the component itself. But if you don't override that menthod, the general root (asset_id = 0 or 1) is taken. I haven't figured it out exactly, but:
See Elin's posting on https://groups.google.com/forum/?fromgroups#!topic/joomla-dev-platform/1IZPG3Vfyvc
As said: we'll get that clear this week.
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Paul Orwig||8/12/12 10:31 AM|
I decided to give the Hello World example a try when I first saw this thread. Right now I am having a problem on step 9 but that's not the point of my post.
The point of my post is just a word of thanks. Thanks to Christophe and Ozgur for creating the original tutorial, thanks for those who updated it since then, and thanks now to Herman and Elin for the way you have helped in this thread, and also for the additional work that is going to be applied to the Wiki.
A really well documented and comprehensive tutorial on this subject is a powerful gift that will help introduce more to Joomla development. The willingness to take time to share knowledge and help others is a great example of what is special about our project and our community.
--You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/Qn4pqyAYlHIJ.
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/12/12 11:51 AM|
Hey Paul, nice to meet you here too! And thank you for your kind words. Community attracts community... someone starts dancing and before you know it you have a JParty. See http://www.youtube.com/watch?v=GA8z7f7a2Pk
As for step 9: as you have probably seen, there was another question that seems related to that same step (problem was: delete button not working):
Curious to what you encountered and hope to help you further, so you can join us at step 14 soon ;-)
Looking at the history of this HelloWorld tutorial I also saw a repository on joomlacode.org (by Antonie de Wilde) from 2008. This HelloWorld really is a long term community project. I also played around with EasyCreator since I'm into Joomla!. That project was started as a tool accompanying this tutorial. Christophe has done a lot on that too. It is now managed by Nikolai Plath (Elkuku) and has "scaffolding" possibilities: it uses a kind of 'template' to set up the basic files of an extension. You 'only' have to transform it to your concrete needs. There were 'templates' for the then existing 1.5-HelloWorld series, but at the moment for 2.5 there are only 2 component-templates from this series (step 1 and step 12). When we have updated the steps of this tutorial, I'd like to add Easycreator-templates for the different steps in this 2.5 wiki-series. I think it can be of good help for educational purposes. See http://extensions.joomla.org/extensions/miscellaneous/development/5908, code on https://github.com/elkuku/EasyCreator
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||El KuKu||8/12/12 6:57 PM|
Thank you Herman for your kind words about EasyCreator, although you are not completely right about its history ;)
Yes, ATM there are only two templates for J 2.5 projects. I already heard some complaints about it.
I am also about to drop the Joomla! 1.5 compatibility (there is a 3.0 branch on GitHub that already contains some work) so maybe this is a good time to update the templates.
So I would love to integrate some new templates for Joomla! 3.0.
Feel free to fork/send pull requests to EasyCreators new home:
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/12/12 11:02 PM|
I'll make EasyCreator-templates together with updating the code in this series of articles. Then the deprecated stuff like JRequest and JError can at the same time be removed. I'll concentrate on 2.5 and send you the pull-requests. Maybe you could add a short history about EasyCreator in a readme-file in your repository; to correct my information and always nice for later reference. Thank you!
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/12/12 11:05 PM|
On Sunday, 12 August 2012 19:14:36 UTC+2, Herman Peeren wrote:
There is a lot of information in https://github.com/joomla/joomla-platform/pull/1416, including the 2 patches.
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/17/12 11:58 AM|
On Sunday, 12 August 2012 17:57:43 UTC+2, TDZWeb wrote:
You can use item-level ACL with com_helloworld (or your own component) without using categories, but you have to adjust the code in _getAssetParentId() of your JTable-extension. In that method you have to return the asset_id of the parent of your item.
If you use categories, you have to return the asset_id of the category the item belongs to. If an item does not belong to a category, you'll have to return the asset_id of the (helloworld)component. If you wouldn't override _getAssetParentId(), the asset_id (normally 1) of the root-asset would be returned. You cannot just copy the code used in com_content for your override. Although that component is the only core-component that uses item-level ACL and you would expect it to be an example for developers, it's _getAssetParentId()-code cannot be just copied for a component with item-level ACL in general: it would return the asset_id of the root-asset if an item doesn't belong to a category. In com_content itself that is fixed by making "uncategorised" a category; so every item (article) belongs to a category.
The code for _getAssetParentId() that is now in the tutorial for com_helloworld is not working completely well for categories: the asset_id of com_helloworld is always returned, so when using categories, the permissions of the categories are not inherited. I'll adjust the code. It will partly be the code as used in com_content, but at the end it won't return the parent::_getAssetParentId(), which would always return 1, but instead we have to put there our current code of returning the com_helloworld asset_id. I'll add some comments to make it clear.
In an earlier posting I said that the root-asset could have asset_id 0 or 1: that is wrong! I hadn't read it carefully enough. The problem was that sometimes in the code the root-asset was identified by asset_id=1 and sometimes by parent_id=0. In the platform that code has been updated (by Elin's Pull Request 1416) to the more correct way of identifying the root-asset: by means of getRootId() of JTableAsset (which is a JTableNested).
I also said, that an asset_id wouldn't be a necessary field in your db-table. Well, it could be done, but especially the JTable-API uses it: in the constructor it sets the $_trackAssets boolean to true if an asset_id column is available in the table and that is a flag that you use item-level ACL. You would have to override quite some code to get it working withouit an asset_id column (and it won't improve the code). So, best practice is to just use it.
In the asset-table an asset is identified with 2 different keys: the asset_id and the name (= the string with the dots). You need both: the string is necessary to find the asset-record if you don't know the asset_id; you can easily compose it from the component-name, the item-name (including eventually "category") and the item-id. But the current name-string doesn't give information about the parent in the asset-hierarchy (other than the component itself); if you would for instance have an asset named com_helloworld.message.2, you cannot know from that name whether it is under a category or not. That is why you need the parent_id column in the assets-table. That column uses a asset_id (otherwise the lft and rgt would not work), so an asset_id is necessary too.
This weekend I'll be disconnected from internet due to family-obigations. Monday is spent to our very active JUG (in the afternoon before the JUG-evening we come together with a group of devs; we'll certainly discuss this thread too). I'll continue working on this from Tuesday onwards.
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Herman Peeren||8/26/12 7:31 AM|
I've updated this MVC-tutorial article #14:
Almost finished. The code in the zip still has to be redone. And some minor changes. It remains work in progress.
As an appetizer the article now starts with steps to get the minimum requirements for a component to comply to Joomla!'s ACL.
After some research I didn't replace the JError-references, as explained in http://docs.joomla.org/Developing_a_Model-View-Controller_Component/2.5/Adding_ACL#Deprecated_classes
I changed the code of _getAssetParentId() in the HelloWorld-JTable a bit:
protected function _getAssetParentId()
// We will retrieve the parent-asset from the Asset-table
$assetParent = JTable::getInstance('Asset');
// Default: if no asset-parent can be found we take the global asset
$assetParentId = $assetParent->getRootId();
// Find the parent-asset
if (($this->catid)&& !empty($this->catid))
// The item has a category as asset-parent
$assetParent->loadByName('com_helloworld.category.' . (int) $this->catid);
// The item has the component as asset-parent
// Return the found asset-parent-id
With this comment:
This code for _getAssetParentId() above uses JTableAsset to retrieve the asset_id of the asset-parent. This is different from the code in the current version of com_content, where the asset_id of the category is retrieved from the #__categories database table. That is another possibility; many ways leading to Rome. In com_content however, if an item would not be under a category, then the asset_id of the global asset is returned. That would of course not be right, but is fixed there by providing a default category "uncategorised", so that an article is ''always'' under a category. That is why you cannot just copy the code of _getAssetParentId() in com_content to your own component. The code above is more general.
I will make the updated zip, dot some i's and cross some t's, before moving on to the next article. If you have any suggestions to improve this article or the series, please let me know.
I've also put up a skeleton for a Wiki-article about how the different parts of the ACL function and work together: http://docs.joomla.org/ACL_Technique_in_Joomla!
Feel free to replace a TODO there with the wanted explanation.
|Re: [jgen] Tutorial problem: Developing MVC Component for Joomla!2.5||Chris Davenport||8/26/12 1:32 PM|
Thanks for the fantastic work you've been doing on improving the MVC tutorial. It's great to see the progress that's been made on it recently.
Keep up the good work,
Joomla Production Leadership Team