Dream Portal is a portal system designed to function with Simple Machines Forum (aka SMF).

It allows you to easily manage your site and webpages in an SMF environment. Place Modules on different actions and non-actions of your SMF forum using a simple drag-and-drop approach. Users can also create and save multiple layouts by name and assign pages to any layout(s). Bundled with Dream Pages and Dream Menu helps put the power and ease of customizing your SMF forum right at your fingertips.

Dream Portal allows you the ability to easily customize your SMF forum and site with many different possibilities helping to make customization truly what dreams are made of!

DreamPortal1.0.5.zip
File size: 221KB
Download count: 1662
DreamPortal1.0.5.tar.gz
File size: 176KB
Download count: 159
Download
Hello, Guest
Please login or register.

 
 
 

Did you miss your activation email?

Re: Menübutton lassen sich nicht löschen.
Last Poster: Tony_R in German on May 14, 2012, 10:18:03 AM


hat mir auch geholfen, vielen dank !

Re: Sologhost went mad. Check this fast!
Last Poster: ThoTh in Chit Chat on May 13, 2012, 03:07:02 PM


Congrats :D

Re: Think I have Everything I need
Last Poster: SoLoGHoST in Chit Chat on May 09, 2012, 01:36:37 PM



Your Recent Image Attachments...
Last Poster: SoLoGHoST in Team Blog on May 07, 2012, 04:13:46 AM


Well, just thought I'd let you all know of the ability to see your 15 most recent image attachments

Re: Inspire Romance
Last Poster: SoLoGHoST in Website Showcase on May 03, 2012, 12:34:22 PM


Looks great!! :)

Author Topic: using module_error()  (Read 1253 times)

0 Members and 1 Guest are viewing this topic.

SoLoGHoST

  • Lead Developer
  • Developer
  • Constant Sleeper
  • *
  • Posts: 2081
  • Wanted... DEAD or ALIVE!
    • Dream Portal
using module_error()
« on: March 16, 2011, 04:14:47 AM »
Ok, many of you probably are NOT aware that Dream Portal has a built in error handling function for your custom modules.  So, while there are more ideas on this function for the future, you can begin using it now within your custom modules.

So, you should call this function within your module whenever you'd like to display an error message of some sort.  No need to include or require the Subs-DreamPortal.php file, this is done automatically.  However, you'll need to return out of your module function after calling this function.

Ok, so let's take a look at the different kind of parameters that this function has and how to use these parameters...

Quote
module_error(string type = 'error', string error_type = 'general', boolean log_error = false, boolean echo = true)

So there are 4 parameters for this function:

type:
You can use any of the following predefined strings for this or you can actually type in a string or use a language $txt string from your language file(s).

The following lists the predefined error strings that you can use.  By default, if you don't specify this parameter, it will use the predefined 'error' error string with just states that there is an error with the module.

STRINGOUTPUTTED TEXT
errorThere is an error with this module!
mod_not_installedSorry, this mod hasn't been installed yet!
not_allowedAccess Denied!
no_languageUnable to load the Language file for this mod!
query_errorError trying to obtain information for this mod.
Mod must be reinstalled!
emptyNo content to display for this module!

Ok, so those are default strings that you can use within the module_error() functions first parameter to output the text.  This text is already loaded within the DreamPortal.english.php file.

Again, if you want to use your own text strings, you can pass these strings into the first parameter of the module_error function as well (either the string itself or the $txt variable can be passed into the first parameter).

error_type:

Basically, this is important if you are logging the error into the SMF Error Log (next parameter), but you could also use it to output red text automatically for Critical errors that you define as critical within your DP module.

possible error types to input here are as follows:

general
critical
database
undefined_vars
user
template
debug

If critical is defined for the error type, than the error message will output red colored text as already mentioned.

log_error:

This is a boolean value (either true or false).  If true is defined for this parameter, than the error gets logged in the SMF Error log, otherwise, the error does not get logged in the SMF Admin Panel Error Log.


echo:

This is a boolean value (either true or false).

If echo = true will output it directly within the module itself, if false, returns the information to be used within a variable.  So, if you want, you can gather all of the different types of errors that occur, place it into an array, and if the array isset() than you can output all of the errors into the module or do whatever you want with those errors.


Well, that is all of the parameters, so now, for an example of how to call it:

Code: [Select]
if (empty($user_info['id']))
{
    module_error('not_allowed', 'critical', true, true);
    return;
}

So, basically what this does is it displays an "Access Denied!" error message within the module for all GUESTS that view that module.  It colors the text that gets outputted, red.  It logs the error within the SMF Admin Error Log, and it echos the text that gets colored red.

Well, if you'd like more examples of how to use this function let me know.  Make sure you return out of your modules function after calling the module_error function as I did in the example above.

Well that is basically all there is to the module_error() function.  If you want to see how I used it for the Download System Module, download the download system module package and take a look at the script.php file inside of the package for it.  The Download System Module is a great example of a Dream Portal Module.

Hope this helps you understand this function more.  Ofcourse, if you want to take a look at the function, module_error, yourself within Subs-DreamPortal.php, that would be a good idea as it is a really small function.

Happy Moduling...
« Last Edit: March 16, 2011, 04:16:19 AM by SoLoGHoST »
#1
****
JaZz
  • Moderate Sleeper
  • Posts: 361
Re: using module_error() - March 16, 2011, 08:34:12 PM
Thanks :) This was very useful for my Twitter module :) Next will be adding error checking for my Facebook module :)

#2
*
SoLoGHoST
  • Constant Sleeper
  • Posts: 2081
Re: using module_error() - March 19, 2011, 01:56:19 AM
Cheers JaZz, you definitely have this module coding down!  Glad you have decided to utilize this for your module(s).  That was it's purpose. 8)

#3
****
JaZz
  • Moderate Sleeper
  • Posts: 361
Re: using module_error() - March 19, 2011, 03:42:41 AM
Thanks for showing me how to use it ;)

#4
*
SoLoGHoST
  • Constant Sleeper
  • Posts: 2081
Re: using module_error() - March 19, 2011, 02:04:50 PM
Sure, may have to start coding a few more modules of my own to add to this wonderful growing collection here at DP.net.

#5
****
JaZz
  • Moderate Sleeper
  • Posts: 361
Re: using module_error() - March 21, 2011, 05:10:09 AM
Do you think you will have the time for that? ;) Seems like you're pretty busy at the moment ;)

If you want to include any of my modules in a DP release feel free to do so :)

#6
*
SoLoGHoST
  • Constant Sleeper
  • Posts: 2081
Re: using module_error() - March 21, 2011, 10:32:18 AM
Thanks for the offer JaZz, you are quite right... kinda busy at other things, but will eventually get to this I suppose.


 

SHOUTBOX NOT FOR SUPPORT!

 Forum Staff