Posts Tagged ‘Tutorials’

Multiple Config Files with Zend_Application

February 28th, 2010

With the recent release of Manuscript, one of the things I added to the application was an installer. The installer is pretty basic and just asks for some database information that gets written to the config files.

This posed a problem. Zend_Config_Writer will only write to a file, not update it. I would need to read in all the sections of the application.ini file (production, testing, development) and take into account any sections added by users and dependencies, remove the old file and write the new one. That seemed very heavy handed and dangerous.

Zend_Config has a merge() function, so the idea came to me to use two config files. Keep the application.ini file for system values that are ‘global’ across installations, and then added a local.ini for things like DB settings. Zend_Config_Writer would just write local.ini settings to the global space and everything would be great. Merge the local settings into the application settings and your done!

A problem surfaced. Manuscript is built using Zend_Application. Zend_Application takes care of all the bootstrapping, reading the config files, and setting up all the dirty stuff for me. It also only takes the path of single config file. I have two config files. Crap.

Luckily Zend_Application doesn’t automatically bootstrap itself, but it does load the configuration immediately. What I ended up doing was this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
 
$localConfigFile = APPLICATION_PATH.'/configs/local.ini';
if(is_file($localConfigFile)) {
    $config = new Zend_Config($application->getOptions(), true);
    $local  = new Zend_Config_Ini($localConfigFile);
    $config->merge($local);
    $application->setOptions($config->toArray());
}
 
$application->bootstrap()
            ->run();

You initialize Zend_Application like normal and call the default application.ini. Zend_Application makes that config file available as an array, so I pull the loaded config back out and pass it into a new array-based Zend_Config ($config in the above). I create a second config ($local) with Zend_Config_Ini.

Using merge(), I merge the $local file into the $config file. This gets me a proper representation of what I wanted. I push this config back into Zend_Application and then call the bootstrap. The bootstrap is none the wiser that it actually is using two config files and my database gets bootstrapped properly!

It is not as clean as I want it to be but it gets the job done and users can override or add their own config information to local.ini and not worry about editing the supplied config file in the release.

Uploading Files using Zend Framework

January 7th, 2010

Uploading files in PHP is easy, if not tedious. A lot of the projects that I work on involve some type of upload of files and after a while it gets old. Doing all the checks to make sure the file is there, generating forms, etc … there must be an easier way, right?

Well, there is. The Zend Framework introduced a few classes to help facilitate uploading and working with files after they make it to the server. Taking advantage of Zend_Form_Element_File and the Zend_File_Transfer_Adapter_Http makes it dead simple to upload a file.

» Read more: Uploading Files using Zend Framework

Doing Development: Setting up VMware Server

July 23rd, 2008

This is the first part in what will be an ongoing set of articles on setting up and getting ready to do development. Before one begins to do any sort of development there needs to be somewhere to do it. With the advent of modern computers and the amazing amount of horsepower that they now contain virtualization makes a great way to set up a perfect, portable environment that gives a developer an incredible amount of control over their work environment.

There are many different virtualization options available now that processors support virtualization directly on the hardware and the aforementioned abundance of computing power. Linux and Windows users can choose from qemu, KVM, VirtualBox, VMware Player/Workstation/Server, Parallels and Xen (Windows misses out on KVM and Xen).

Out of that list, VMware has been in the virtualization business for a long time and as a result have wonderfully robust codebases for virtualization. It is because of this I will be setting up VMware Server, a free-as-in-beer product that allows a user to create virtual machines. The added benefit is that the end user can easily move this VM from machine to machine and even between VMware products.

» Read more: Doing Development: Setting up VMware Server

Install Debian Etch on an older G3 iMac

February 11th, 2008

One thing that stops many people from trying Linux is that either they don’t want to go through the hassle of dual-booting their machine and possibly loosing everything in the process, or that the ease of use with virtualization technology such as VMware and VirtualBox make non-commitment to an OS trivial. If one is serious about using an alternative OS, I think it’s better to use it on a machine all by itself.

What better way to do that than to get a cheap computer, in this case an old iMac, and load Linux on it. While the process isn’t exactly the same as doing this on an x86 PC, once the OS is loaded one gets a feel for how everything works. You’ll also get the advantage of a real, multitasking OS instead of MacOS 9 or earlier.

» Read more: Install Debian Etch on an older G3 iMac

Howto: Install IPCop 1.4.15 Firewall (Part 3 – Securing Your Network)

August 8th, 2007

Now that IPCop is installed and you can access it from anywhere in the world via OpenVPN, now comes securing your network and making sure that the bad guys stay out while making sure that what goes on in your network is logged.

Read on for more.

» Read more: Howto: Install IPCop 1.4.15 Firewall (Part 3 – Securing Your Network)