Tutorial problem: Developing MVC Component for Joomla!2.5

2,085 views
Skip to first unread message

TDZWeb

unread,
Aug 6, 2012, 4:47:48 PM8/6/12
to joomla-de...@googlegroups.com
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.

Swapnil Shah

unread,
Aug 6, 2012, 4:56:27 PM8/6/12
to joomla-de...@googlegroups.com
Hey, 

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. 

Regards, 


Neil
Sent from my iPhone
--
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/-/wfvieQvaOhMJ.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

Herman Peeren

unread,
Aug 7, 2012, 1:19:14 AM8/7/12
to joomla-de...@googlegroups.com
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:
  • I'll now just add $this->canDo = $canDo; just under :$canDo = HelloWorldHelper::getActions($this->item->id);. That is the smallest change to accomplish this.
  • But if we add a property to that class, we better do that on the same spot as where the other properties are added: under "Assign the Data" in the display()-method. If we add $this->canDo HelloWorldHelper::getActions($this->item->id); in the display()-method, then in the addToolBar()-method we should leave out $canDo = etc. and change all $canDo to $this->canDo. 
  • to make it nicer we should "declare" all properties at the top of the class, in this case as private or protected, make them null and do assignments like that as much as possible in a constructor. Then you can immediately see what properties are used. Declaring variables is also the preferred coding style in Joomla!; see: http://developer.joomla.org/coding-standards.html 3.7 and 3.8.5.

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.

Cheers,
Herman

Herman Peeren

unread,
Aug 7, 2012, 1:37:12 AM8/7/12
to joomla-de...@googlegroups.com
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.

TDZWeb

unread,
Aug 7, 2012, 3:11:24 AM8/7/12
to joomla-de...@googlegroups.com
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".

Herman Peeren

unread,
Aug 7, 2012, 3:49:13 AM8/7/12
to joomla-de...@googlegroups.com
On Tuesday, 7 August 2012 09:11:24 UTC+2, TDZWeb wrote:
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".

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.
Also see:

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.

TDZWeb

unread,
Aug 8, 2012, 12:35:25 PM8/8/12
to joomla-de...@googlegroups.com
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).
<section name="category">
  <action name="core.create" title="JACTION_CREATE" description="COM_CATEGORIES_ACCESS_CREATE_DESC" />
  <action name="core.delete" title="JACTION_DELETE" description="COM_CATEGORIES_ACCESS_DELETE_DESC" />
  <action name="core.edit" title="JACTION_EDIT" description="COM_CATEGORIES_ACCESS_EDIT_DESC" />
  <action name="core.edit.state" title="JACTION_EDITSTATE" description="COM_CATEGORIES_ACCESS_EDITSTATE_DESC" />
  <action name="core.edit.own" title="JACTION_EDITOWN" description="COM_CATEGORIES_ACCESS_EDITOWN_DESC" />
</section>

At least now all the functions of the component itself seems to work. I can add, edit and delete all the parts.

Herman Peeren

unread,
Aug 8, 2012, 12:51:34 PM8/8/12
to joomla-de...@googlegroups.com
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.

Ciao,
Herman

Herman Peeren

unread,
Aug 8, 2012, 1:32:33 PM8/8/12
to joomla-de...@googlegroups.com
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.


On Wednesday, 8 August 2012 18:35:25 UTC+2, TDZWeb wrote:

TDZWeb

unread,
Aug 8, 2012, 1:36:51 PM8/8/12
to joomla-de...@googlegroups.com
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.

Herman Peeren

unread,
Aug 8, 2012, 1:54:31 PM8/8/12
to joomla-de...@googlegroups.com
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.

TDZWeb

unread,
Aug 8, 2012, 2:43:00 PM8/8/12
to joomla-de...@googlegroups.com
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.

Herman Peeren

unread,
Aug 8, 2012, 3:26:39 PM8/8/12
to joomla-de...@googlegroups.com
Are you (even as superuser) part of the "Special" Viewing Access Level?
See http://docs.joomla.org/Access_Control_List/1.6-2.5/Tutorial

TDZWeb

unread,
Aug 8, 2012, 3:42:43 PM8/8/12
to joomla-de...@googlegroups.com
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:

TDZWeb

unread,
Aug 8, 2012, 6:27:20 PM8/8/12
to joomla-de...@googlegroups.com
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:
<?php echo $this->form->getLabel('rules'); ?>
<?php echo $this->form->getInput('rules'); ?>

I added the following field to the admin/models/forms/helloworld.xml (this time by peeking at com_content's article MVC):
<fieldset name="rules" label="COM_HELLOWORLD_FIELDSET_RULES">
<field name="rules" type="rules" label="JFIELD_RULES_LABEL"
translate_label="false" class="inputbox" filter="rules" component="com_helloworld"
section="message" validate="rules" />
</fieldset>

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.

elin

unread,
Aug 8, 2012, 9:37:21 PM8/8/12
to joomla-de...@googlegroups.com
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
global
component global
component category
item

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.


Elin

TDZWeb

unread,
Aug 9, 2012, 12:28:54 AM8/9/12
to joomla-de...@googlegroups.com
Are you saying the #_helloworld table is incomplete? There is no asset_id (or access for that mater) column in the table.

Herman Peeren

unread,
Aug 9, 2012, 4:07:05 PM8/9/12
to joomla-de...@googlegroups.com
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

Herman Peeren

unread,
Aug 9, 2012, 4:10:39 PM8/9/12
to joomla-de...@googlegroups.com
Great! This is a good contribution to use to improve the Wiki-information. Thank you!

Swapnil Shah

unread,
Aug 9, 2012, 4:12:15 PM8/9/12
to joomla-de...@googlegroups.com
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.

To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.


--
Sent from Gmail Mobile

Herman Peeren

unread,
Aug 9, 2012, 4:22:06 PM8/9/12
to joomla-de...@googlegroups.com
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.

Cheers,
Herman

TDZWeb

unread,
Aug 9, 2012, 4:33:02 PM8/9/12
to joomla-de...@googlegroups.com
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.

elin

unread,
Aug 9, 2012, 9:17:30 PM8/9/12
to joomla-de...@googlegroups.com
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.



Elin

Herman Peeren

unread,
Aug 10, 2012, 2:14:24 AM8/10/12
to joomla-de...@googlegroups.com
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.

Herman

Herman Peeren

unread,
Aug 10, 2012, 2:18:20 AM8/10/12
to joomla-de...@googlegroups.com
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.

On Friday, 10 August 2012 03:17:30 UTC+2, elin wrote:


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.




OK, I will also make a summary of that on this Wiki-page.

Herman

elin

unread,
Aug 10, 2012, 9:13:24 AM8/10/12
to joomla-de...@googlegroups.com
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.

Elin

TDZWeb

unread,
Aug 10, 2012, 2:22:09 PM8/10/12
to joomla-de...@googlegroups.com
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?

Herman Peeren

unread,
Aug 10, 2012, 4:05:04 PM8/10/12
to joomla-de...@googlegroups.com
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

Ciao,
Herman

elin

unread,
Aug 11, 2012, 7:03:36 AM8/11/12
to joomla-de...@googlegroups.com
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.

TDZWeb

unread,
Aug 11, 2012, 8:18:57 AM8/11/12
to joomla-de...@googlegroups.com
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:
  • Adding asset_id column to the #_helloworld table.
ALTER TABLE`#__helloworld` ADD COLUMN `catid` int(11) NOT NULL DEFAULT '0';
  • Adding the rules field to the admin/models/forms/helloworld.xml
<fieldset name="accesscontrol">
<field name="asset_id" type="hidden" filter="unset" />
<field name="rules"
type="rules"
label="JFIELD_RULES_LABEL"
translate_label="false"
filter="rules"
validate="rules"
class="inputbox"
component="com_helloworld"
section="message"
/>
</fieldset>
  • Adding a category section to admin/access.xml.
<section name="category">
<action name="core.create" title="JACTION_CREATE" description="COM_CATEGORIES_ACCESS_CREATE_DESC" />
<action name="core.delete" title="JACTION_DELETE" description="COM_CATEGORIES_ACCESS_DELETE_DESC" />
<action name="core.edit" title="JACTION_EDIT" description="COM_CATEGORIES_ACCESS_EDIT_DESC" />
<action name="core.edit.state" title="JACTION_EDITSTATE" description="COM_CATEGORIES_ACCESS_EDITSTATE_DESC" />
<action name="core.edit.own" title="JACTION_EDITOWN" description="COM_CATEGORIES_ACCESS_EDITOWN_DESC" />
</section>
  • Modifying the display function of the helloworld view in admin/views/helloworld/view.html.php, to define the property canDo.
public function display($tpl = null) 
{
// Assign the Data
$this->form = $this->get('Form');
$this->item = $this->get('Item');
$this->script = $this->get('Script');
$this->canDo = HelloWorldHelper::getActions($this->item->id);
 ...

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.

elin

unread,
Aug 11, 2012, 9:14:24 AM8/11/12
to joomla-de...@googlegroups.com
Thanks Herman! That tutorial is really turning into a great collaborative document.

Elin

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

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.

Herman Peeren

unread,
Aug 11, 2012, 3:08:25 PM8/11/12
to joomla-de...@googlegroups.com
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).

In HelloWorldTableHelloWorld::bind():

        // Bind the rules.
        if (isset($array['rules']) && is_array($array['rules']))
        {
            $rules = new JAccessRules($array['rules']);
            $this->setRules($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_FIELDSET_RULES="Message Permissions"
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. 

Swapnil Shah

unread,
Aug 11, 2012, 3:12:57 PM8/11/12
to joomla-de...@googlegroups.com
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. 

--
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/-/0hsrIyHp0vAJ.

To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

TDZWeb

unread,
Aug 11, 2012, 3:19:56 PM8/11/12
to joomla-de...@googlegroups.com
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

Cheers
Ståle
To post to this group, send an email to joomla-dev-general@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-general+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

Herman Peeren

unread,
Aug 11, 2012, 3:41:37 PM8/11/12
to joomla-de...@googlegroups.com
On Saturday, 11 August 2012 15:14:24 UTC+2, elin wrote:
Thanks Herman! That tutorial is really turning into a great collaborative document.

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.

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:
http://docs.joomla.org/Adding_ACL_rules_to_your_component
Will put references in the footer of "our" ACL-article.

Herman Peeren

unread,
Aug 11, 2012, 3:45:47 PM8/11/12
to joomla-de...@googlegroups.com
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...

Herman Peeren

unread,
Aug 11, 2012, 3:53:41 PM8/11/12
to joomla-de...@googlegroups.com
On Saturday, 11 August 2012 21:12:57 UTC+2, Neil wrote:
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.

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.

Ciao,
Herman

Herman Peeren

unread,
Aug 11, 2012, 3:56:00 PM8/11/12
to joomla-de...@googlegroups.com
We can also once do a Skype chat or maybe a Google+ hangout with more people about the subject.

Herman Peeren

unread,
Aug 12, 2012, 4:00:55 AM8/12/12
to joomla-de...@googlegroups.com
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/

TDZWeb

unread,
Aug 12, 2012, 11:57:43 AM8/12/12
to joomla-de...@googlegroups.com
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?

Herman Peeren

unread,
Aug 12, 2012, 1:14:36 PM8/12/12
to joomla-de...@googlegroups.com
On Sunday, 12 August 2012 17:57:43 UTC+2, TDZWeb wrote:
 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?

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:
  • I don't know yet if the only problem is in the original _getAssetParentId() method of JTable or (also) somewhere else
  • I don't know if the problem still exists if you override _getAssetParentId(), like we do in our example
  • maybe the problem is only that it is done a bit stange in JTableContent and some developers have taken that as an example (because it is the only core component using item-level ACL). In that case: we have no problem with our example.
  • it looks like it could introduce mistakes if the same root asset has both a 0 and a 1 as asset_id

See Elin's posting on https://groups.google.com/forum/?fromgroups#!topic/joomla-dev-platform/1IZPG3Vfyvc
Maybe she can explain some more about what the problem exactly is. And maybe explain something about the changes that have been made in the platform for that. That could save some looking-up time. All links to discussions and code welcome.

As said: we'll get that clear this week.

 Ciao,
Herman

Paul Orwig

unread,
Aug 12, 2012, 1:31:04 PM8/12/12
to joomla-de...@googlegroups.com
Hi all,

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.

Thanks,

paul



--
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.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.

Herman Peeren

unread,
Aug 12, 2012, 2:51:20 PM8/12/12
to joomla-de...@googlegroups.com
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):
https://groups.google.com/forum/#!msg/joomla-dev-general/OqoPiWfs_Eo/NznA5l0IvyoJ
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

Ciao,
Herman

El KuKu

unread,
Aug 12, 2012, 9:57:39 PM8/12/12
to joomla-de...@googlegroups.com
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:

https://github.com/elkuku/EasyCreator

Regards,
Nikolai

Herman Peeren

unread,
Aug 13, 2012, 2:02:28 AM8/13/12
to joomla-de...@googlegroups.com
Hi Nikolai,

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!

Kind regards,
Herman

Herman Peeren

unread,
Aug 13, 2012, 2:05:00 AM8/13/12
to joomla-de...@googlegroups.com
On Sunday, 12 August 2012 19:14:36 UTC+2, Herman Peeren wrote:

Maybe she can explain some more about what the problem exactly is. And maybe explain something about the changes that have been made in the platform for that. That could save some looking-up time. All links to discussions and code welcome.

 There is a lot of information in https://github.com/joomla/joomla-platform/pull/1416, including the 2 patches.

Herman Peeren

unread,
Aug 17, 2012, 2:58:45 PM8/17/12
to joomla-de...@googlegroups.com
On Sunday, 12 August 2012 17:57:43 UTC+2, TDZWeb wrote:
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?

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.

Herman Peeren

unread,
Aug 26, 2012, 10:31:54 AM8/26/12
to joomla-de...@googlegroups.com
I've updated this MVC-tutorial article #14:
http://docs.joomla.org/Developing_a_Model-View-Controller_Component/2.5/Adding_ACL

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);
        }
        else
        {
            // The item has the component as asset-parent
            $assetParent->loadByName('com_helloworld');
        }

        // Return the found asset-parent-id
        if ($assetParent->id)
        {
            $assetParentId=$assetParent->id;
        }
        return $assetParentId;
    }

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.

Chris Davenport

unread,
Aug 26, 2012, 4:32:28 PM8/26/12
to joomla-de...@googlegroups.com
Hi Herman,

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,
Chris.


--
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/-/Ccpdykj_FTAJ.

To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.



--
Chris Davenport
Joomla Production Leadership Team

Reply all
Reply to author
Forward
0 new messages