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.
> 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.
> -- > 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-dev-general@googlegroups.com.
> To unsubscribe from this group, send email to joomla-dev-general+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.
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.
> 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.
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 (HelloWorld*s*) 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.
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".
kl. 07:37:12 UTC+2 tirsdag 7. august 2012 skrev Herman Peeren følgende:
> 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 > (HelloWorld*s*) 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.
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*.
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).
> 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
> *.
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.
On Wednesday, 8 August 2012 18:35:25 UTC+2, TDZWeb wrote:
> 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).
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:
> 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).
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.
kl. 19:32:33 UTC+2 onsdag 8. august 2012 skrev Herman Peeren følgende:
> 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:
>> 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).
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.
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.
kl. 19:54:31 UTC+2 onsdag 8. august 2012 skrev Herman Peeren følgende:
> 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.
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:
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.
kl. 21:42:43 UTC+2 onsdag 8. august 2012 skrev TDZWeb følgende:
> 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:
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.
> 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.
> kl. 21:42:43 UTC+2 onsdag 8. august 2012 skrev TDZWeb følgende:
>> 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:
> 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
> On Wednesday, August 8, 2012 6:27:20 PM UTC-4, TDZWeb wrote:
>> 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:
>> 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.
>> kl. 21:42:43 UTC+2 onsdag 8. august 2012 skrev TDZWeb følgende:
>>> 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:
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.
> 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.
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.
On Thursday, August 9, 2012, Herman Peeren wrote:
> 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.
> --
> 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-dev-general@googlegroups.com <javascript:_e({}, 'cvml',
> 'joomla-dev-general@googlegroups.com');>.
> To unsubscribe from this group, send email to
> joomla-dev-general+unsubscribe@googlegroups.com <javascript:_e({},
> 'cvml', 'joomla-dev-general%2Bunsubscribe@googlegroups.com');>.
> For more options, visit this group at
> http://groups.google.com/group/joomla-dev-general?hl=en-GB.
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 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.
kl. 22:22:06 UTC+2 torsdag 9. august 2012 skrev Herman Peeren følgende:
> 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").
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.
On Thursday, August 9, 2012 4:10:39 PM UTC-4, Herman Peeren wrote:
> Great! This is a good contribution to use to improve the Wiki-information. > Thank you!
> On Thursday, 9 August 2012 00:27:20 UTC+2, TDZWeb wrote:
>> 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:
>> 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.
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.
On Thursday, 9 August 2012 22:33:02 UTC+2, TDZWeb wrote:
> 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.
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.