Part 1: Setting Up – A not so quick quickstart to Zend Framework

2

Category : Programming

Welcome to a series of tutorials to introduce the most important features of Zend Framework. During this series we will cover many Zend Framework classes and at the end you will be able to have a good overview of this powerful framework.

In this first part, we will cover the setup. So, basically, we will describe how to setup MAMP (if you are using Mac OS X, but the procedure is very similar windows and Linux), followed by setting up Zend Framework, Eclipse PDT, ZendDebugger, XDebugger and finally PHPUnit.

I hope you like it!

Setting Up MAMP

Form now, we will always refer to MAMP, but the procedures are basically the same for Windows and Linux (XAMPP – http://www.apachefriends.org/en/xampp.html)

First of all, download it (http://www.mamp.info/en/index.html) and install it by dragging it MAMP (MAMP Pro is a paid version) to the Applications folder.

Now, go the folder Applications/MAMP and open MAMP. To start your servers (apache and mysql) just click “Start Servers”. You will see that the red lights will become green indicating that the servers are up and running. Now click Open Start page, and your default web browser will open and a welcome page will be displayed.

If everything went as described, you now have apache and mysql running in your machine. :)

Now, we will change the default ports for apache and mysql. To do this, click in preferences on MAMP, go to tab Ports and pick the port you want (ex: Apache Port: 80, Mysql port: 3306).

Click and Stop Servers, and then Start Servers. If the lights become green, you are ready to go to the next step.

Setting Up Zend Framework Library

Download the Zend Framework Full Package from http://framework.zend.com/download/latest

After downloading, extract the contents to a folder and move the “library/Zend” folder to your MAMP:

sudo mv library/Zend/ /Applications/MAMP/bin/php5.3/lib/php/Zend

By moving the zend folder, now you will have Zend Framework supported by default in your installation and you will not need to copy the Zend framework to the library folder of all of your projects.

Another useful tool that comes with Zend Framework is the zf tool. There is no general rule to install it. Our suggestion is (considering you are in the zend framework extracted files folder):

sudo mv bin/zf.sh /usr/local/bin/zf

sudo chmod +x /usr/local/bin/zf

sudo mv bin/zf.php /Applications/MAMP/bin/php5.3/lib/php/

Now, open “zf” to edit:

sudo vi /usr/local/bin/zf

And replace @php_bin@ with /Applications/MAMP/bin/php5.3/bin/php and @php_dir@ with /Applications/MAMP/bin/php5.3/lib/php/

Save the file. Now you will need make “php” that comes with MAMP executable, since the zf tool needs to run it. So, type in a terminal:

sudo chmod +x /Applications/MAMP/bin/php5.3/bin/php

Test the zf in the terminal. Open the terminal and type “zf” (without the quotes). If usage instructions appear, everything is correct.

Installing Eclipse + PDT

Go to Eclipse PDT website (http://www.eclipse.org/pdt/downloads/) and download the all in one version.

Extract the files and move the entire Eclipse folder to your Applications folder.

We will see how to create PHP Project in the Part 2 of this series.

Adding ZendDebugger and XDebug support

Download the latest Studio Web Debugger from http://www.zend.com/products/studio/downloads (i.e. ZendDebugger-20100729-darwin-uni.tar.gz.gz – 32bit – for Mac OS X). Extract the files, type the following commands:

sudo mkdir -p /Applications/MAMP/bin/php5.3/zend/lib/ZendDebugger/php-5.3.x/

sudo mv ZendDebugger-20100729-darwin-uni/5_3_x_comp/ZendDebugger.so /Applications/MAMP/bin/php5.3/zend/lib/ZendDebugger/php-5.3.x/

Now, edit the php.ini file (/Applications/MAMP/conf/php5.3/php.ini) and add the following lines at the end of the file (inside the [Zend] section):

zend_extension=/Applications/MAMP/bin/php5.3/zend/lib/ZendDebugger/php-5.3.x/ZendDebugger.so

zend_debugger.allow_hosts=127.0.0.1/32

Comment the following lines (adding “;” in the beginning of the line):

; zend_extension = “/Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/xcache.so”
; zend_extension_ts = “/Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/xcache.so”

And finally uncomment the line (to enable XDebugger):

zend_extension=”/Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so”

Now, restart MAMP, open Start Page and click on phpInfo. You should see something like this:

If you can see that XDebug and Zend Debugger are installed, you can proceed to the next step.

We will see how to use eclipse to debug your project using Zend Debugger in the Part 2 of this series.

Setting Up PHPUnit

Download the latest stable release from http://pear.phpunit.de/get/ and extract it. Move the PHPUnit folder to php5.3 lib:

sudo mv PHPUnit/ /Applications/MAMP/bin/php5.3/lib/php

Now, edit phpunit.php and replace the @php_bin@ with ‘/Applications/MAMP/bin/php5.3/bin/php’. And replace the first line “#!/usr/bin/env php” to “#!/Applications/MAMP/bin/php5.3/bin/php”.

Finally, rename phpunit.php to phpunit and move the file to /usr/local/bin:

sudo mv phpunit.php /usr/local/bin/phpunit

And adjust the permissions to make the file executable

sudo chmod +x /usr/local/bin/phpunit

Now type phpunit in a terminal and you should see an usage message.

Another interesting feature is the code coverage. Since we have enabled the XDebug in the MAMP installation, now you can PHPUnit including code coverage support ;)

Configuring Virtual Hosts form your projects

The last step will describe how to create virtual hosts in your machine to allow you to have a different “address” to each project.

First of all, edit the /private/etc/hosts:

sudo vi /private/etc/hosts

Now, add one line for each host name you want, for example:

127.0.0.1     zfguide

The nest step is to create/edit an apache configuration file:

sudo vi /Applications/MAMP/conf/apache/vhosts.conf

And add the following lines:

<VirtualHost *:80>
     ServerName zfguide
     DocumentRoot /Users/myhome/Workspaces/eclipse/zfguide/public/
     <Directory /Users/myhome/Workspaces/eclipse/zfguide>
          Options Indexes FollowSymLinks MultiViews
          AllowOverride All
          Order allow,deny
          allow from all
     </Directory>
</VirtualHost>

You can repeat these steps to as many hosts as you need!

To conclude, let’s enable the Virtual Hosts in Apache.

sudo vi /Applications/MAMP/conf/apache/httpd.conf

And add the following lines to the end of the file:

NameVirtualHost *:80
Include /Applications/MAMP/conf/apache/vhosts.conf

Restart MAMP (if you don’t have the folders defined in your vhosts.conf, create them before restarting apache), open your favourite web browser and type “http://zfguide” (or anything you’ve chosen as host name). :)

And that’s it !! Now you have everything you need to start programming using Zend Framework and also have important tools to help you in the development process.

The next part of this series will describe how to create a project using zend framework.

Popularity: 40% [?]

Top 15 Google Chrome extensions and scripts

Category : Top list

We’ve selected our preferred google chrome extensions. This list is in no particular preference order (just click in the extension title to go to its website):

1. Better Gmail (unofficial)

It is a compilation of many great userscripts and userstyles for Gmail. Features: remove ads, fix page width, reposition print button, hide chat, hide footer, hide invite friends field, show unread message count in tab favicon, show in attachment icons the attachment filetype, add row highlight on mouse over, handle e-mail (mailto) links to use gmail. You can choose whether enable or not each feature.

2. Chrowety

A twitter client for google chrome. This extension eliminates the need of using a separate twitter client or always keep a browser tab opened to monitor your twitter. An alternative to this extension is the ChromedBird. Chrowety has more features and a better look and feel, but is more unstable than ChromedBird. Both extensions are very good !

3. Google Quick Scroll

Google Quick Scroll is a browser extension that helps you find what you are searching for faster.After you click on a Google search result, Quick Scroll may appear on the bottom-right corner of the page, showing one or more bits of text from the page that are relevant to your query. Clicking on the text will take you to that part of the page.

4. Chrome link checker

This extension checks availability of files stored in file servers (e.g: rapidshare) even before clicking on the link.

5. Google Dictionary

View google definitions as you browse the web.Just double-click any word to view its definition in a small pop-up bubble.

6. RSS Subscription Extension

Very useful extension that auto-detects RSS feeds on the page you are reading and display an RSS icon in the address bar. When you click in the RSS icon, you will be able to preview the content and subscribe to this RSS using different services.

7. Sexy Undo Close Tab

Undo your closed tabs. This extension adds a button that allows you to undo as many closed tabs as you want. You can also view the closed tabs list and select the tab you want to re-open.

8. Stop Autoplay for YouTube

This extension stops autoplay for youtube, and keeps the movie loading (buffering).

9. XML Tree

This extension displays xml data in a friendly way, much more readable than the default way that google chrome displays.

10. Chrome notepad

Add a simple and useful notepad into your google chrome. This extension has another great feature: allows notes synchronization in a very smart way and without using 3rd party tools (by using google chrome bookmarks sync)

11. Image Preview

Very useful extension that finds links to images and youtube videos in the web page you are reading and replaces the link with popup.

12. Proxy Switchy!

If you want to manage and switch between multiple proxies in a easy and simple way, this is the extension that you are looking for.

13. Slideshow

Its description says: “Turn your favorite photo sites, such as Flickr, Picasa, Facebook, and Google Images into a slideshow”, and this is exactly what this extension does. After loading the page, you will see a bar at the bottom of the window, just click on the picture and enjoy the slideshow.

14. Google translator

This extension adds a button that opens a popup where you can easily translate texts and words.

15. User Script: Gmail Favicon Alerts 3

Alerts you to the how many unread messages you have in your Gmail Inbox through distinct Favicons.

Do you know other great extension ? Share you with us, comment !

Don’t forget to follow us on twitter and receive updates everytime I post something here: http://twitter.com/goodcomptips

Popularity: 10% [?]

Worth a try: GMail Conversation View

Category : Worth a try

If you love the way that gmail organize your emails into conversations, but also need a more complex mail client like mozilla thunderbird, maybe now you have a better way to do this.

This is not as good as gmail conversations yet, but it is much better than thunderbird’s default threaded view. This thunderbird extension enables conversation view in Thunderbird, including your own messages in the conversation.

Take a look at https://addons.mozilla.org/en-US/thunderbird/addon/54035/ and try using it. This is a very active development, so we can expect an even better extension in a short term.

Don’t forget to follow us on twitter and receive updates everytime I post something here:http://twitter.com/goodcomptips

Popularity: 7% [?]