Archive for the ‘PHP’ Category

Quick start to Magento theming

Wednesday, August 25th, 2010

This started out as an e-mail to a colleague to bring him up to speed on how to theme Magento. While writing it I realized that this knowledge would be beneficial to many others and posted it on my neglected blog. Here are a handful of link to help you with the wizardry that is Magento templates.

Magento Designer’s Guide

Magento Design Terminology

Magento Knowledge Base – Theming & Design

Magento WIki – How to create a new package / theme

Magento Wiki – Themes and Template Customization

Magento Theme Hierarchy Changes

Dependencies & Compiling PHP 5.3.x on openSuSE

Friday, March 26th, 2010

When compiling PHP from source sometimes you’ll bang your head against a wall while trying to resolve dependencies. After a mild head banging session I’ve discovered that if you add –lib-dir=lib64 to ./configure while compiling PHP it will fix your problems.

My main issue was that I kept getting the following error:

configure: error: libjpeg.(a|so) not found.

I looked in /usr/lib64 and both libjpeg.a and libjpeg.so were there. I specified –with-jpeg-dir=/usr/lib64 and continued to receive the above error. It wasn’t until I added the –lib-dir=lib64 that made everything work.

We’re Hiring!

Wednesday, July 29th, 2009

Imaging walking through the warehouse to your desk and hearing the sounds of motorcycle engines roaring as the smell of racing fuel fills the air. Does this sound like a great way to start your morning? If so, we have a job for you.

The company I work for RidersDiscount.com is looking for a PHP Developer to help us build our next generation web presence. RidersDiscount.com is a successful, growing online retail company that is seeking candidates in the West Michigan area to fill a full-time on-site position. Below is a link to the official job posting.

PHP Developer Position at RidersDiscount.com

If you are interested feel free to respond to the craigslist job posting or you can email me your resume at aj at ridersdiscount dot com.

Storing Magento blocks in a subfolder

Wednesday, June 24th, 2009

While integrating Solr with Magento I decided to create a superclass for the facet blocks to extend since the majority of their functionality was rather similar. I started by creating a file named Facet.php with the class Company_Search_Block_Facet in app/local/Company/Search/Block that extended the Magento_Core_Block_Template class. I next created the subfolder app/local/Company/Search/Block/Facet to store all my facet blocks and a file named Size.php that extended Company_Search_Block_Facet. The tricky part was getting it to work properly. I attempting to add a facet blocks to the right column using the following code.

$this->getLayout()->createBlock(’search/facet/size’);

The problem was it loaded my superclass Company_Search_Block_Facet instead of my child class Company_Search_Block_Facet_Size. After digging through some of Magento’s source code I found the solution. You need to use an underscore instead of a forward slash to load blocks in subfolders.

$this->getLayout()->createBlock(’search/facet_size’);

Now I can easily store my blocks in a subfolder keeping my Block folder nice and tidy.

Multiple PHP Environments with MacPorts

Wednesday, March 25th, 2009

A while back on Twitter I mentioned how I love that I can use ports to switch between different PHP environments with the flick of a switch. Demian Turner responded asking for more info on the subject spawning the creation of this post. That was 3 months ago and before it could collect too much dust Karl Tiedt provided the insistence inspiration to get off my ass and finish it, as he put it.

When I started working at OpenX my need to switch between various PHP environments arose. As it was required that I test all my code on multiple version of PHP since we supported a wide range of PHP versions. Basically I had it setup so I could test my code on 3 version (5.0.x, 5.1.x, & 5.2.x) of PHP 5 and 3 versions of PHP 4. The solution had to allow me to quickly switch environments with as little human interaction as possible. This is where MacPorts and a little shell scripting magic came into play. The nice thing about ports is you can compile the same application with different configurations and switch between them on the fly.

This is by no means a complete tutorial it’s a quick and dirty get started guide on how you can switch between PHP 4 and PHP 5 as quickly as possible using Apache 2 as the backend. This setup can also be extended to switch between various backends. For example switching between apache + mod_php5 and lighttpd + php5-fcgi. I won’t go into detail but by the end of this guide you’ll be able to figure it out.

Let’s get started by installing Apache 2

sudo port install apache2

Now that Apache 2 is installed we can move on to getting PHP 4 and PHP 5 compiled. Run the command below to use ports to install PHP 4 as a module for Apache 2 and PostgreSQL 8.3 since it’s a dependancey. Ports automates the installation of software. It downloads, configures, compiles and then installs PHP 4 including adding the necessary configuration lines to your Apache configuration.

sudo port install php4 +apache2 +macosx +pcntl +pear +postgresql83 +sockets +sqlite +t1lib +tidy

After it’s installed we need to deactivate PHP 4 otherwise the PHP 5 installation will error out since you can not have both the PHP 4 and PHP 5 ports activated at the same time.

sudo port deactivate php4

Next, we’ll install PHP 5

port install php5 +apache2 +macosx +pcntl +pear +postgresql83 +sockets +sqlite +t1lib +tidy

Note that the PHP 5 port installation will not modify your Apache httpd.conf file and you must do it manually. Once you have both ports installed it’s rather simple to switch between the two by running the two commands below

port deactivate php4

port activate php5

MacPorts will swap out the necessary files for you. However you must manually swap out the php.ini and your Apache httpd.conf file. This was definitely not going to cut it as I needed to be as effortless as possible so I whipped up a little shell script to get the job done.

#!/bin/sh
case “$1″ in
‘php4′)
/opt/local/apache2/bin/apachectl stop
/opt/local/bin/port deactivate php5
/opt/local/bin/port activate php4
cp /opt/local/etc/php4.ini /opt/local/etc/php.ini
cp /opt/local/apache2/conf/httpd.php4.conf /opt/local/apache2/conf/httpd.conf
/opt/local/apache2/bin/apachectl start
;;
‘php5′)
/opt/local/apache2/bin/apachectl stop
/opt/local/bin/port deactivate php4
/opt/local/bin/port activate php5
cp /opt/local/etc/php5.ini /opt/local/etc/php.ini
cp /opt/local/apache2/conf/httpd.php5.conf /opt/local/apache2/conf/httpd.conf
/opt/local/apache2/bin/apachectl start
;;
esac

Save the above script as php-switch in /opt/local/bin and make it executable. Then copy /opt/local/etc/php.ini to /opt/local/etc/ as php4.ini and php5.ini. Also do this for Apache’s /opt/local/apache2/conf/httpd.conf file to /opt/local/apache2/conf naming them httpd.php4.conf and httpd.php5.conf. Execute the script with either ‘php4′ or ‘php5′ as the parameter. The script will then shuts down Apache, deactivates the opposite PHP module, enables the specified PHP module, copies the necessary config files and then starts Apache.

Next lets install another version of PHP 5 that has the MySQL drivers instead of PostgreSQL

sudo port install php5 +apache2 +macosx +mysql5 +pcntl +pear +sockets +sqlite +t1lib +tidy

When switching between two versions of the same app that are compiled with different configurations you must explicitedly express the variants. For example to activate the PHP 5.2.5 port with PostgreSQL driver you’d run the following command

sudo port activate php5@5.2.6_1+apache2+macosx+pcntl+pear+postgresql83+sockets+sqlite+t1lib+tidy

Don’t worry if you forget the variants because if you try to activate a port without being explicted MacPorts will remind you.

root# port activate php5
—> Activating php5
—> The following versions of php5 are currently installed:
—> php5 @5.2.6_1+apache2+macosx+pcntl+pear+postgresql83+sockets+sqlite+t1lib+tidy (active)
—> php5 @5.2.6_1+apache2+macosx+mysql5+pcntl+pear+sockets+sqlite+t1lib+tidy (active)Error: port activate failed: Registry error: Please specify the full version as recorded in the port registry.

This should be enough to get you up. One thing that I don’t cover here that needs to be mentioned is PHP modules usually need to be compiled against different versions of PHP. For example if you use XDebug to debug your applications you’ll need a module compiled agains both PHP 4 and PHP 5. Use all code at your own risk.

PHP Development Tools for Eclipse

Thursday, March 8th, 2007

Yesterday I had the opportunity to sit in on the “PHP Development Tools (PDT)” talk here at EclipseCON. I haven’t used PDT since it’s inital release last year so it was great to see what they’ve been doing. Yossi Leon the Project Leader provided an overview of the PHP perspective and the various views. Then he went on to demonstrate the debugger which currently only supports Zend’s close sourced debugger protocol. However he did mention that there is a patch for Xdebug support if you’re feeling brave and want to compile PDT. For the most part PHPEclipse provides all the features that PDT does but there are a good handful of features not in PDT that PHPEclipse currently supplies. However, there were a couple neat features that I’d like to see make their way into PHPEclipse. Personally, I attened this talk because I’ve had one question on my mind since Zend proposed a PHP plugin for Eclipse. That question being, “Will Zend be releasing a commerical version of PDT?” Come to find out PDT is NOT a plugin itself but a framework which a plugin can be build upon. After learning this I had to reword my question to, “Will Zend be releaseing a commercial IDE based on PDT?” Which of course the answer to is yes. I was unable to find out when but Yossi did say it should be surfacing soon.

Now knowing this raises another question, “Should PHPEclipse switch to PDT as it’s underlying framework or do we continuing developing the current framework.” This is a question that only can be answered by the PHPEclipse developers and community. I personally wouldn’t have an issue with the switch because Yossi informed me that they will be creating a generic debugger interface to support multiple debuggers. This is something that the PHPEclipse developers have been discussing for quite some time since we have support for both DBG and Xdebug. The only concern left is what influence will Zend have upon PDT because of their interest in developing a commercial IDE upon it. Having a 100% open source project such as PHPEclipse involved in the development of PDT might be a good idea. What do you think should PHPEclipse switch to PDT?

Scott Adams, AJAX Toolkit Framework, Mylar, DTP and PHPEclipse

Wednesday, March 7th, 2007

Scott Adams was the Keynote Speaker to kick off EclipseCON. He started off with a story on how he became an cartoonist and the evolution of Dilbert. Then went into how to be successful and briefly talked about his past. Afterwards he showed some comics and shared a story behind each of the comics on why they didn’t quite make the cut. It was an amusing morning that started off with a ton of laughs.

Next I attended a talk on the AJAX Toolkit Framework. I’ve been meaning to check this out for quite some time but never got around to it because the Firebug plugin for Firefox did everything I needed, or so I thought. I have now come to the conclusion that I was wrong and since have installed ATF. It has all the benefites of Firebug plus so much more. If you’ve never had a chance to check out AFT I strongly encourage you to do so. It just so happens that as I finished writing this paragraph a gentleman came over to the table and set down a handful of CDs from Backbase titled “AJAX Starter Kit.” Quite ironic if you ask me. Looks like I have yet another AJAX pluging for Eclipse to give whirl.

After the AFT talk, I attended “Task-focused programming with Mylar” presented by the Project Maintainer Mik Kersten. I’ve been using Mylar for roughly the last 6 months and it has completely changed the way I work. I have never been so orginized or more productive. Mylar allows you to build a context related to the current task (bug, feature enhancement, etc) at hand and forget about everything else. Thus making it so that when you switch between tasks all the files that are related to that task are reopened, bringing you back to exactly where you left off. No more trying to remember what files, classes, or methods are related to the specific task, Mylar handles it all for you. Tasks are imported from your bug tracking software (Bugzilla, Trac, and a few others) or you can add personal task locally. Task context can also be shared between developers which is an incredible feature. You can also see incoming and outgoing changes to tasks from within Eclipse. Since ATF provides a Mozilla implementation I no longer have a reason to have Firefox open. Now that I can update tickets in Trac and view what I’m working on from within Eclipse. Mik provide a detailed look at what can be done with Mylar and what to expect in the upcoming 2.0 release. He also annouce a new partnership with Tasktop which extends Mylar bringing it’s functionality to desktop applications such as your email client, web browser, word processor and web services. Which will allow you to add context outside of Eclispe related to a task. This plugin is a must have for every programmer.

This talk was followed up with a long awaited lunch which. After I attended a talk on the Data Tools Platform Project (DTP) which was very interesting and I learned a good deal on the internal workings of the plugin. Including how to create my own dialect for a RDBMS. I wish I could of stayed for the entire talk but my presence was required at the Open Source Pavilion causing me to have to leave about a half hour early.

In the Open Source Pavilion I had the opportunity to demo PHPEclipse for roughly 6 hours. No sooner did I sit down and setup the laptop did someone show up for a demo. Just as I was in the final moments of my first demo John Ward (presented the tutorial I attended on Monday) stopped by. I was expecting him because on Monday I had mentioned to him that I would be doing demos of PHPEclipse on Tuesday. It just so happened that he was working on a PHP project and was looking for a PHP plugin with a functional debugger. All the ones he tried including PHPEclipse he couldn’t get the debugger to work properly. Being the debugger guru that I am from the past couple of years spent on IRC helping people setup PHPEclipses’ debugger. I had him well upon his way to debugging bliss after about a half hour, he couldn’t of been happier. I continued to demo PHPEclispe to several more people and finally the person I had been waiting for showed up. I knew eventually someone of the Zend would stop by and that someone did.

He admitted right off the bat that he had never looked at PHPEclipse and told me he was one of the QA people for PHP Development Tools (PDT). After which he asked if I’d be kind enough to give him a tour which I delightfully accepted. I started off with an overview of the workspace layout which he complimented on how intuitive it was. Next, I explained how the code completion and syntax highlight worked and finally I did an in depth demo of the debugger. The only thing he had to say as he left was PHPEclipse was very impressive. So far this has been the highlight of the conference for me. It’s always nice to demo a product for a competitor and them being blown away. Now I have no choice to return the favor, as I finish writing this I am on my way to the PDT talk.

PHPEclipse @ EclipseCON

Saturday, March 3rd, 2007

I am honered to be representing PHPEclipse at this years EclipseCON in Santa Clara, CA. Philippe Ombredame and I will be in the Exibit Hall from 2:15pm to 8pm on Tuesday, March 6th 2007. There will be a demo of PHPEclipse and we’ll be available to answer any questions you might have. If you’ve never had a chance to see PHPEclipse in action here’s your chance and if you have, stop by and introduce yourself. It’s always great to others from within the community.  I’ll see ya there.

dBug

Wednesday, February 28th, 2007

I stumbled across this tool last Oct and tagged it with “toblog” on del.icio.us but I never got a chance to actually write about it. dBug is var_dump()’s sexy twin. It outputs detailed information about the selected variable that is beautifully formated yet human readable. It truly comes in handy when you’re trying to debug an issue on a remote server. You can check the output on the examples page.

Chiara_PEAR_Server Release Droplet for Mac OS X

Friday, December 15th, 2006

Brett Bieber has just released a release droplet for Mac OS X. This makes pushing a release of a new package completly painless. For full details check out the post “Chiara_PEAR_Server Release Droplet for Mac OS X” on his blog. For those of us that don’t run OS X and want to create our own script, Brett was kind enough to create the Salty_PEAR_Server_RemoteReleaseDeployer package which allows you to do just that.