revjim.net Rotating Header Image

ezPublish: PHP Script to Create a new object

After about 10 hours of debugging and troubleshooting, I've finally figured out what has been causing problems when writing a PHP script to create a new object in ezPublish. It's so simple, and so stupid, that I almost want to bang my head against a wall.

When a new object is created, it must be stored before you can edit a version of it. ezContentClass::instantiate() does this for you. However, what they don't tell you is that, in order to store the object, it must have access to the database. This seems simple enough, but it's pretty confusing once you get started. You see, when you write a script, you use the ezScript class to take care of establishing all the database connections and whatnot. And the ezScript class never complains if it can't make that connection. To make matters worse, ezContentObject doesn't complain when it can't store() its data either.

The reason that ezScript couldn't connect to the database was because it couldn't find my INI files. I figured that having them in my include_path was enough to help it find them. But apparently, it doesn't use the include_path to look. If they aren't under /settings/, they won't be found. Therefore, the problem is simply this:

You must run your script from within the root directory of your ezPublish install!!

This simple mistake will mean the difference between the script working, and the script not working and never complaining.

Additionally, even though ezINI accepts a RootDir parameter to tell it where to look for stuff, ezScript doesn't seem to be capable of passing this information along. So there are no options as far as trying to trick it to run from another location. This is just plain silly. Workable, but silly.

Share and Enjoy:
  • Facebook
  • StumbleUpon
  • Digg
  • del.icio.us
  • Google
  • Reddit
  • Technorati
  • Furl
  • Spurl
  • Live
  • Pownce
  • TwitThis