Does anyone have a good example of a well written MODx module that’s not too complicated, but uses renderFormElement() and other standard MODx functions?
I’m making my first ever module, and am having trouble with implementing a good simple clean MODx module.
I take it that I owuld be better off using standard files like header.inc.php, and so on, but when I use them I get all sorts of errors.
-
☆ A M B ☆
- 24,524 Posts
You might want to check out the tutorials I wrote on making a database management module; see my sig for the guest manager user login.
Thanks for the link, the article was most interesting. So what you recommend is to just use ordinary PHP for the modules.
I am doing that on my current modules, but what I would prefer to do is use all the crunchy MODx goodness, like the header.inc.php, and footer.inc.php, as well as being able to use standard MODx date and rich text controls without having to cut and paste a ton of HTML from one place to another.
That said, I would be very interested in seeing your database.php file.
-
☆ A M B ☆
- 24,524 Posts
Each article has the relevant files available for download. The download links are in the left sidebar of the article pages.
The first article explains how to make a module look like the default MODx manager theme:
There are two files that the MODx Manager uses for all of its main frames; manager/includes/header.inc.php and manager/includes/footer.inc.php. In the case of the module management frame, it uses the manager/actions/static/modules.static.action.php file. I "borrowed" the parts from these files that I wanted to provide the look-and-feel of the module. Since it’s a module, and not a part of the Manager, the variables (such as which manager theme is being used by the site) are not available, but these values can be retrieved through the $modx object, which is available to modules. So instead of the variables you need to use $modx->config[’manager_theme’] in the links for the css files.
<link rel="stylesheet" type="text/css" href="media/style/<?php echo $modx->config[’manager_theme’]; ?>/style.css" />
Do the same for links to the icons.
Thanks for the information, it answered my question fully.
Does anyone know if there will come a time when we can use these modules without a load of errors popping up? It would save a ton of time.
As I understand it, modules as such will not exist as of 0.97 (a new improved system will replace the concept). But they can be made to work now without errors, albeit without a full serving of MODx crunchy goodness. If you’re having specific problems that you can’t resolve, post your code so that we can try to help you figure them out.
So, probably best to copy sotwells methods now, and learn what the new method is when 0.97 comes out.