Welcome
Mar 24, 2013Welcome to my blog
Articles By Bob Ray
Here is a list of all of the site's Blog articles, sorted by date.
Welcome to my blog
Part I of Installing MODX
Part two of Installing MODX
Part three of Installing MODX
The ins and outs of getting a good solution to your problem by asking a question in the MODX forums
Understanding isfolder and hasChildren() in MODX Revolution
How to keep users from editing the pages of other users in NewsPublisher
Select and display users based on the content of an extended field in the User Profile
How to create Top Menu items in the Manager that let you edit files directly
Make sure your MODX Articles Blog doesn't create a security risk for your site.
Why Articles blog posts disappear, and how to get them back
How to find and change Lexicon strings displayed in MODX Revolution.
Protecting pages with a simple snippet
I recount a frustrating bug hunt and give some tips on debugging CMPs
Create a simple snippet to show TV-based drop-down lists in the front end.
Making sense of the addPackage(), loadClass(), and getService() methods
Demystifying the MODX base classes: xPDOObject and xPDOSimpleObject
Many new MODX programmers stumble over the anomalies in the Names and Primary Keys of MODX Objects
Use a simple snippet to show the value of Context Settings from a Context other than the current one
Information on using the Articles blog templates
Everything you always wanted to know about instantiating MODX
Let users in specific user groups see only pages of a certain age.
Make selecting a parent more user-friendly in NewsPublisher
Make selecting the Template more user-friendly in NewsPublisher
A simple snippet to retrieve Resources in, or out of a Resource Group
Checking and unchecking checkboxes with JavaScript buttons
When a user re-visits a form, the checkboxes will be set as they were the last time the form was submitted.
A method to use MODX lexicon strings that will work inside or outside of MODX
Step-by-step instructions for creating an RSS feed for your MODX Articles blog.
Tips and techniques for displaying date fields in MODX
A client-friendly way to show selected teasers with getResources
Add Author Bio pages to your MODX Articles Blog
The safe way to set an element property
Hide specific menu items using a permission setting
Two ways to control the order in which your MODX blog articles are displayed
Two utility snippets that save and restore the structure of a customized MODX Top Menu
Handling the extended fields of the MODX user profile in code
Creating MODX Manager Top Menu Items in PHP
A look at how typical pre-2.2 MODX CMPs work
A utility snippet to help change your web site automatically with the seasons.
Techniques for getting into the Manager when you're locked out
A look at how JavaScript and PHP interact and how JavaScript is used in the MODX Manager
A simple snippet to get the pagetitle of the current resource's parent.
A look at the inner workings of an http request
A snippet to get any field from the parent of the current resource.
How to safely remove old versions of transport packages
Finding various bits of code in the MODX core
Recursively traverse directories and list or process every file found
Extending the DirWalker class to perform custom processing on files as they are found
Use DirWalker to produce a valuable report on MODX System Events
Add a navigation Jumplist to the DirWalker Output
Handling the problem of duplicate event invocation
Use a plugin to clear the cache for selected resources in MODX Revolution
A snippet to show the full name of the person who edited the current page and, optionally, the date of the last edit.
Understanding the process MODX uses to publish and unpublish resources automatically
Make content appear and disappear without the overhead of JQuery
An updated, best-practices, look at the architecture of a MODX Custom Manager Page (CMP) in MODX 2.2+.
A look at various methods for getting TV values in MODX
Getting the TV values for children of the current resource in MODX.
Things to check when your CSS fails to load
You might not want to say "Hello (anonymous)" on your pages. Here's how to change that.
Some advice on nesting MODX tags
A quick tip for checking on the existence of a database table in PHP code
Extending the modUser object for speed and efficiency
Realize amazing speed increases by extending the modResource object in MODX
Susan Ottwell's adaptation of my LogPageNotFound extra puts the page-not-found report in a Manager dashboard widget
A snippet to produce a link to the first child of the current resource, or any other resource
A look at System Events and Plugins from the inside.
A look at creating user groups in a MODX plugin.
Using a regular expression to validate and normalize the zip code field for our plugin
Using a plugin attached to OnDocFormSave to modify resource fields and TV values
Dramatically reduce page-load times by using a plugin to place formatted data in the introtext (summary) field.
A snippet to show the age of a resources using various time units
An inside look at the MODX getOption() method, with some things about it you almost certainly didn't know.
The ins and outs of how properties sent in a snippet tag arrive in the snippet.
Converting a slow conditional output modifier solution to a fast snippet
A very fast and efficient method for getting field values in MODX, from Jason Coward.
Getting and interpreting MODX boolean (Yes/No) fields in code
Retrieving and handling resource date fields like editedon and createdon in code the fast way with getValue()
Retrieving TV values fast with getValue()
Retrieving the main content field of resources and elements the fast way with getValue().
There are some advantages to putting your MODX sites in subdirectories
Building a new MODX site with old site still running
Launch a floating Git bash window inside PhpStorm with a single click
Some tips and tricks for using Git with MODX
A quick way to display multiple fields from the current resource's parent
A quick note on how to use straight MySQL statements in MODX
A very fast way to retrieve selected object fields without getting the whole object
A PDO method for bypassing the conversions made by the set() method.
How to write raw values to the database with the fromArray() method.
Using prepared statements is good, but calling prepare() over and over in a loop is bad. Here's how to avoid it.
Binding statement parameters to class variables so they can be used anywhere in the class
Using a small utility snippet to create complex search criteria for the &where property of getResources or pdoResources or any other snippet that uses a &where property.
A snippet that will create a report giving the number of pages that use each template, with separate data on published and unpublished resources.
Add pagetitles to the template report created in the previous Blog article.
A simple utility snippet to test user permissions
A look at various methods for adding MODX users to user groups in code
Make changes in user status take effect immediately
A more readable alternative to some complex if statements in PHP.
The first in a series of articles that will look at the stages of development for a simple MODX snippet, with some side trips into design principles and progressive enhancement
The second in a series of articles about MODX snippet development
The third in a series of articles about MODX snippet development best practices.
Fourth in a series of articles about MODX snippet design and development.
Fifth in a series of articles on MODX Snippet best practices
The sixth in a series of articles on MODX snippet best practices
The final article in a series on MODX snippet development best practices
How to use MODX language tags to internationalize a page without using a snippet
A plugin to log failed logins and brute-force hacking login attempts
Some thoughts about making your MODX site more secure
Show a list of upcoming articles to attract return visits
Modifying the Upcoming Teaser snippet to work on other resource types
Modifying the Upcoming Teaser snippet to work with multiple resource types
Get the results of a call to getResources in PHP code (and a useful trick for the &where property).
Remove selected words with a custom output modifier
Use "find and replace" pairs to modify resource content
Use an associative array to do multiple string-replace operations
Making sure that your extra package removes everything it installs
How to convert a comma-separated list in a snippet property to an array in your snippet
Creating an associative array with keys and values from a snippet property
Create a string from an array with implode()
Display formatted content from an associative array with implode()
More details about how the final argument to $modx->getOption() works
A nifty extra by Sergey Shlokov makes the MODX error log a pleasure use.
Using a plugin to set the Unpublish Date to a fixed interval from when it was published.
Don't make this disastrous error when getting a user's profile
The first in a series of articles on redirecting users when they log in
Redirecting users on login based on the time or season
Redirect users based on a User Setting
Redirect users on the basis of user-group membership using a user-group setting
Redirect users on login by checking group membership directly
Redirect users based on a User Group setting, but control the order in which group memberships are tested
Use group IDs to speed up the membership test
Redirect users to a Manager page on login
Finding the code that produced a line in the MODX error log
Getting error information when the screen goes blank
Searching for regex patterns across multiple lines
Using the user-related resource fields in code
A snippet to get the full name for any user-related resource field without modifying the snippet code.
Get user info for any user-related resource field
Using a Tpl Chunk to display user-related resource fields
Producing a report showing resources created by the current user
Use a snippet property to customize the user resource report
Sorting the results of the User Resource Report
Get all resources acted on by the user in a single query
Fixing the PHP error: Fatal Error Cannot Redeclare Function
Putting our function inside a class to avoid collisions
Fixing the "Cannot redeclare class" PHP error
Graceful handling of include files that don't exist
How autoloaders work and several example autoload.php files
PHP namespaces explained, with some examples
Letting your autoloader use your namespaces to locate class files
Use your own code, or an external service to authenticate users
Second in a series of articles about bypassing the Manager Login process
Using a single plugin to create and authenticate users
Exploring the MODX config file and MODX path issues
How to avoid and fix problems caused by making too big a jump in MODX versions.
Using the correct path and URL references to CSS, image, JS, PHP, and other files in code and in HTML
Send registration email to the admin (or anyone else) rather than the user
What to do if Gmail keeps warning you that the email from your site's contact form might not be from the email's user
Create a widget to toggle a Yes/No System Setting with the click of a button
Debugging an elusive 403 error for a single page
An easy way to make the user's email address serve as their MODX username
Recommended practices for giving different users different capabilities in the MODX Manager
Using CSS to hide the help button in the MODX Manager
Hiding the help button in the Manager with CSS
Hiding the help button in the Manager with CSS
Using CSS to hide other Manager Page Elements
Hiding the System Menu in the Manager using CSS
Hiding Resource Panel Elements in the Manager using CSS
Control which Manager pages a plugin will execute on
Hide the "Is Static" field for MODX Elements using CSS
How to create and use utility snippets in MODX Revolution
Perform search-and-replace operations on all resources with this utility snippet
Using a utility snippet for multiple search-and-replace operations
A brilliant plugin from Bruno Perner (Bruno17), to keep MODX Manager users from seeing anyone outside their primary group in the user grid.
Getting the value of a TV for a particular resource via the modTemplateVarResource object without touching the modTemplateVar (TV) object.
How to handle the modTemplateVarResource object when the value for a particular resource might be set to the default value of the TV.
Setting TV values with modTemplateVarResource based on user input from the Register form
Example code for using modTemplateVarResource to set a TV based the value of one or more other TVs
A trick that lets you put the user's full name in your Registration email
Fall back to the username if the fullname field is empty
First in a series of articles on MODX Weblinks.
Creating, setting, and saving a new modWebLink object in PHP code.
Setting the properties of a Weblink in code.
How to change the page that a Weblink points to
A look at the similarities and differences between Symlinks and Weblinks
Using PHP code to create a new Symlink
How to update an existing Symlink using PHP code
Advanced Symlink options using the forward_merge_excludes System Setting
Advanced symlink techniques using the forward_merge_excludes System Setting
A look at problems that can keep you from saving a resource
News features, improvements, and bug fixes in NewsPublisher 3.0
MODX settings -- types and usage
Understanding the order of precedence of different types of settings
How to create new System, Context, User Group, or User Settings in the Manager.
Displaying setting names, descriptions, and areas, in more than one language
Example showing the practical use of a setting
Using settings in the PHP code of a snippet or plugin
Naming files and objects in a way that makes using them easier and more efficient
Using PHP code to create MODX System Settings
Using PHP to create MODX Context Settings
Using PHP to create MODX User Group settings
Using PHP code to create MODX User Settings
How to update various kinds of MODX settings in PHP
Using a snippet to automate the process of updating multiple settings
Now there's a much easier way to change the username of the (anonymous) user
First in a series of articles on using a plugin to modify MODX Manager pages
Adding buttons to the Create/Edit Resource Manager page with JavaScript in a plugin attached to OnDocFormRender
Using onClick vs addEventListener to make screen buttons execute JavaScript functions
Making the Edit Draft and Edit Original buttons do what they're supposed to do
Creating a functional Delete Draft button
Adding a delete draft button that works.
Creating the Staged Resource only when appropriate
Reloading the Create/Edit Resource Panel when the Save button is clicked
Knowing whether it's time to update a resource with the staged version
Adding the code that actually updates the Original Resource when the stage date arrives
The final article in this series shows how to transfer TV values from one resource to another
Here's a trick for getting the TV values for a resource that's in another context
Putting MODX Manager Top Menu items where you want them
Show hidden resource fields like editedon, editedby, and createdby on the Create/Edit Resource panel
A tour de force of techniques for pulling information from the web and from various kinds of files
The skeleton code for the project to create documentation files for the MODX docs site
A generic cURL function for getting content or raw data from remote sites
Using the simple_html_dom class to extract data from a string of raw HTML code.
Extracting data from MODX repository pages
Using the GitHub API to extract information
Using James Brumond's Git class to get data from a local Git repository
Counting the number of files in a directory and its subdirectories with DirWalker
A general-purpose time formatting function, and parsing a Markup readme.md file to get the authors of an extra
Writing the finished documentation files
This final article in the series contains the full code, all in one place
How to control the order in which TVs are displayed on the Create/Edit Resource panel
A snippet to help find the code where placeholders are being set
Finding placeholders in included files
Handling included files that use MODX constants
Using a Media Source to show files in a moved and/or renamed core directory in the Manager's File tree
Make the MODX Manager's search function search by ID
A quick tip showing how to hide the Time field when editing MODX date TVs in the Manager
Select from a drop-down list of users and show the selected user's information on a page
Use an @SELECT TV to show only users from a single user group in a drop-down list.
The best way to change the message users see after entering the wrong credentials during Login
Methods for creating dynamic JavaScript in MODX
Creating JavaScript in PHP and injecting it into a page
Putting JavaScript in a chunk with placeholders
Asking MODX to generate the URL for our dynamic JavaScript
Fix a security vulnerability with target="_blank"
Using a plugin to add noopener noreferer to link tags.
A snippet to fix the links, then save them to the database
Improving the logic that updates the link tags
Fix link tags with target="_blank" in TVs
Final version of the code to correct link tags with target="_blank" in template variables
A plugin to correct link tags with target="_blank" as objects are saved to the database
An easier way to create Custom Manager Pages (CMPs) in MODX
Make our easy CMP do an actual search
Making our CMP do a real search and report the results
Adding the controller file
Using JavaScript with a real processor
A quick look at what an API is and does
How to Find Out if You Can Do a Fast-forward merge in Git *without actually merging*
A look at some Git techniques for comparing things
A look at comparing a file with previous versions in PhpStorm
Comparing two files and observing the differences in PhpStorm
Comparing entire directories in PhpStorm
Handling lexicon strings for System Settings in a transport package.
Removing pesky URLs containing typos from your browser's MRU list
Finding symlinks to a given resource
Displaying all symlinks on a MODX site
Provide links to edit each object in the Manager
What to do when a widget crashes the MODX Manager
Stop MODX from inserting type="text/javascript" when injecting scripts
Several methods for seeing the language you prefer in a MODX extra
Using $modx->runsnippet() to pass data between two snippets
Using a file to pass data between two snippets
Passing data between two snippets using a $_SESSION variable
Passing data between snippets using cookies
Pass data between two snippets using User Settings
Passing data between two snippets using a custom database table
How to get MODX to forward users to their own pages on login
Using a plugin to let users *edit* their own page on login
Maintaining structure and indentation when pasting code in PhpStorm
What causes the "Call to a member function get() on null" error
Preventing the "Error: Call to a member function get on null" with a sanity check.
More efficient code for the sanity check preventing the "Error call to member function get on null."
Put a message in the error log when the resource has an invalid parent
Preventing Chrome from caching your code
Prevent Chrome from caching anything with a convenient Chrome extension
Clear the MODX cache fully with the CacheClear extra
Keep multiple users from logging in with the same credentials
Introduction to htaccess rules and conditions
Understanding regular expressions used in htaccess files
Understanding .htaccess rewrite conditions
Understanding .htaccess rewrite rules
Some useful .htaccess rules and how they work
Useful .htaccess tricks that don't involve rewrite conditions and rules
New .htaccess rules in Apache 2.4.0
Making sure MODX can find your files in both development and live environments
Retrieving the paths from the namespace object
What to do about the assets URL
Three hundred and counting!
Creating a test to determine if a particular MODX System Event has fired
Firing MODX System Events in your own code
How to create custom System Events for use with your code
Making sure your code tests for equality properly
How to make your MODX plugin execute, or not execute in one or more specific contexts
Enable or disable plugins in the Manager based on Resource Context
Enable or disable plugins based on the values of specific resource fields
Enable or disable plugins based on the values of specific TVs
Code to get the path of a MODX Media Source
Code to get Relative Paths and URLs from a MODX Media Source
Changing the value of all TVs for resources under certain parent folders.
Getting the current year in code
Controlling page content based on the year
Creating links based on the year
Finding bugs in your code when the error message is not helpful or there is no error message
Forwarding users to a year-dependent page automatically
A case where MODX resources save with no errors but don't show up in the Resources Tree
Some tips on using back-ticks and displaying code in the MODX Forums
Why some TV values may not be shown by getResources or pdoResources
What to do if your extra requires the installation of other extras
Use a PHP script to create new blog Articles
Creating a blog Article using a MODX chunk for the content
Handling placeholders when creating Articles with PHP
Using the resource/create processor to create new Articles.
Using a plugin to create related pages after a new resource is created
A look at how to use built-in and custom hooks with the FormIt extra
How software testing can change your life
Defining the most common kinds of software tests.
Managing dependencies between PHP packages
Installing the Composer dependency manager
Installing available packages with the Composer dependency manager
Using the Composer dependency manager to install Codeception and PhpUnit
Organizing and configuring our testing system
Running unit tests from the command line
A HelloWorld unit test to make sure everything works
A unit test that actually tests something
Running Codeception unit tests inside the PhpStorm code editor
An example of a bad (and virtually untestable) constructor
Introducing better error handling and unit testing it with using stubs
Fixing some problems with the user class
Creating a test for a separate validator class using a data provider
Moving validation to a separate class
Adapting our User class to handle external validation
Updating the User class to pass the new tests
What's seriously wrong with the YouTube TV user interface
Using Inversion of Control (IOC) and Dependency Injection (DI), to improve your code
Adding Dependency Injection to the User class
Using mock objects to test how often a method is executed
A review and evaluation of the series on unit testing and a preview of code coverage
Introduction to code coverage and tips for installing code coverage tools
Interpreting code coverage methods and some advice about using them
Performing integration testing, with a more complex data provider
Creating a test version of MODX and using it as a fixture in testing
Using MODX as a fixture to do integration testing with the Codeception Db module
Using Codeception helper methods
Creating integration tests for MODX processors
Considering what a functional test would look like for MODX
Our first Acceptance test
Acceptance test for a simple contact form in MODX
Creating the contact form that our acceptance test will pass
Logging in to the MODX in an acceptance test
Creating a Codeception PageObject for the login page
More information on creating XPath Locators
Using Codeception to Test the MODX Manager
Creating page objects for the Manager Dashboard and for the Create/Edit Users panel
Final version of our user text for the MODX Manager
Using Codeception to test the MODX resource security system
Creating the step object for our resource protection acceptance test
Using data files to provide the user and resource data we'll need for our test.
Creating a new page object containing the CSS and XPath locators we'll need to navigate through the MODX manager.
A variety of instructive XPath examples
A basic skeleton for a test of the MODX security system for protecting resources
The finished version of our Resource Protection Test
Using Codeception environments to alter the way tests are run
Using separate environment files to control environments used in a test
Creating a separate bootstrap file for MODX 3
Creating separate page objects for MODX 2 and MODX 3
Making the code changes necessary for our test to run in MODX 3
A trick for running MODX 2 and MODX 3 tests with a single command