1
Mamba
Tip for Permissions Tab errors with $permform->render()
  • 2011/3/18 14:50

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


In some modules we have a "Permissions" Tab to set Access/View/Other permissions for individual groups to, for example, Topics/Categories (like in xFAQ module).

But when we have Categories that we want to set the permissions for, and they are empty, then XOOPS generates on

$permform->render();


errors similar to this:

Quote:
Warning: array_keys() expects parameter 1 to be array, null given in file /class/xoopsform/grouppermform.php line 129
Warning: Invalid argument supplied for foreach() in file /class/xoopsform/grouppermform.php line 129

I found a solution in another module, that resulted in this code in xFAQ:

//check if topics exist before rendering the form and redirect, if there are no topics    
$result_view $xoopsDB->query("SELECT topic_id, topic_title FROM " $xoopsDB->prefix("xfaq_topic") . " ");
if (
$xoopsDB->getRowsNum($result_view)) {
    
    echo 
$permform->render();
    
} else {
redirect_header("topic.php"2_AM_XFAQ_NOPERMSSETfalse);    
}

I hope, it will help somebody.

As always, the goal is to have zero warnings/notices in our code

If somebody else has Tips or Best Practices that could be used in the "module refreshment" that we're doing, please share them with us.
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

2
Tarik
Re: Tip for Permissions Tab errors with $permform->render()
  • 2011/3/18 15:08

  • Tarik

  • Not too shy to talk

  • Posts: 170

  • Since: 2010/2/3 1


or by using the object class

//check if topics exist before rendering the form and redirect, if there are no topics    

if ($topicHandler->getCount()) {
    echo 
$permform->render();
} else {
    
redirect_header("topic.php"2_AM_XFAQ_NOPERMSSETfalse);    
}
Some people like what you do,
-- some people hate what you do,
---- but most people simply don’t give a damn.

3
Mamba
Re: Tip for Permissions Tab errors with $permform->render()
  • 2011/3/18 16:16

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


Fantastic! Much better!

Thank you so much!

If you see anything in the code in those old modules that could be improved/simplified, please share with us, and help us making it better.

That's what the Blue Move was all about
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

Login

Who's Online

406 user(s) are online (319 user(s) are browsing Support Forums)


Members: 0


Guests: 406


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits