Setting the Time Zone for PHP 5.3.0+

While working with PHP 5.3 scripts, you may have run into an error that tells you you need to set the time zone for PHP 5.3.0.  This might happen when upgrading or installing a CMS or other script in your hosted or local web environment. A comment error message I’ve run across several times when working with MODX, SilverStripe, Processwire, etc. is:

date.timezone option in php.ini must be set in PHP 5.3.0+

Another common error message is:

To use PHP 5.3.0+, you must set the date.timezone setting in your php.in.

In this brief post I’ll describe a couple of different ways to deal with this.

Continue reading “Setting the Time Zone for PHP 5.3.0+”

MODx Evolution: Creating a Simple Custom Snippet Part 4 – Optimize with Caching

Part 0: Introduction
Part 1: Write and Test the PHP Script
Part 2: Create the Snippet
Part 3 – MODx API, Placeholders, Chunks

In the fourth part of this brief series on creating a custom MODx Evolution snippet, we’re going to do some optimizing to make our snippet a little more efficient.  So far the snippet seems to be working as expected and is pulling in the feeds as needed.  However, it’s a little inefficient.  The way things are set up now, every time someone refreshes the page, the script fetches a new copy of the rss feed from the coding pad, or whatever source you’re pulling your feeds from. If you have a heavily trafficked site where people spend a lot of time on your site and visit many pages (thus, for example, constantly refreshing your snippet call in the sidebar), this can be resource heavy on both your side slowing your website down, and also on the web server that you’re pulling the feeds from.  We can mitigate this by implementing caching.

Continue reading “MODx Evolution: Creating a Simple Custom Snippet Part 4 – Optimize with Caching”

MODx Evolution: Creating a Simple Custom Snippet Part 3 – MODx API, Placeholders, Chunks

Part 0: Introduction
Part 1: Write and Test the PHP Script
Part 2: Create the Snippet

So far we have created the raw PHP script and tested the code outside of MODx.  We’ve started the process of transforming this script into the rssfeedFetcher snippet and we have it working on the Learn MODx website.  We’ve learned how to add optional parameters with default values to our call and everything seems to be working as expected. At the close of the last segment, I mentioned that our snippet is still relatively inflexible because the user has no control over how the output looks.  We’re going to rectify this today by tapping a little into the MODx API to create placeholders and utilize chunks to allow for some templating and customization of the output.

Continue reading “MODx Evolution: Creating a Simple Custom Snippet Part 3 – MODx API, Placeholders, Chunks”

MODx Evolution: Creating a Simple Custom Snippet Part 2 – Create the Snippet

Part 0: Introduction
Part 1: Write and Test the PHP Script

In the last installment of this brief series we went through the process of creating the raw PHP script that will form the basis of our snippet. We tested the code outside of MODx and it seemed to work pretty well. In this part, we’re going to start the process of transforming this script into a MODx snippet.  As I said before, I will be working on the Learn MODx website that we built during the MODx Beginner series of tutorials.  My goal is to use the snippet to add one or maybe two sections of MODx related feeds to the sidebar of the website.  But first, we need to create the snippet itself, so let’s get to work 🙂

Continue reading “MODx Evolution: Creating a Simple Custom Snippet Part 2 – Create the Snippet”

MODx Evolution: Creating a Simple Custom Snippet Part 1 – Write and Test the PHP Script

Part 0: Introduction

In the introductory post, I explained briefly what we’re going to create, made some important disclaimers, and blew some hot air around.  In this part, we’re going to get our hands dirty by diving in and writing the PHP script and testing it outside of MODx to make sure it works. In general, I think this is a good idea because it allows you to iron out any purely PHP issues in your code before dealing with the MODx side of things. Chances are that even after you’ve tested it and ported it into MODx, you’ll end up adding more PHP logic and stuff but if you can test most of it outside MODx first, it should potentially save you some headaches and debugging time when working inside MODx.  This is especially important because once inside the MODx editor there’s no syntax highlighting, automatic indenting and all that other good stuff.

With that in mind, let’s go ahead and create our script.

Continue reading “MODx Evolution: Creating a Simple Custom Snippet Part 1 – Write and Test the PHP Script”