Zend Framework 1 and Doctrine 2 integration – modular setup

This is a follow up post to my previous “Zend Framework 1 and Doctrine 2 integration“.

I’ve created a new branch on my Github project “zf1-doctrine2″. The “modular_setup” branch shows how we could setup Zend Framework with the modular approach, while still be able to use Doctrine 2 as the ORM for each module.

Oh well, the idea is to make each module decoupled with the rest of the application, so really, you could use whatever database handling mechanism in each module.

Check it out from my Github project here.

Reference

20 June 2010 at 12:11 - Comments

Zend Framework 1 and Doctrine 2 integration

Doctrine 2 is in beta. It is for sure one of the most exciting things that caught my attention recently.

As a Zend Framework user, I started looking into ways to integrate Doctrine 2 with Zend Framework (currently in version 1).

The same as any other times, the solutions are already out there. The integration’s already been done by Giorgio Sironi’s nakedphp project.

So … I borrowed code from nakedphp and put up a skeleton ZF projects myself.

My sample project is available on Github. You can find it here.

Have a play, let me know if anything. Hope it’ll help people like myself, who cannot wait to try out new and cool things.

Reference

19 June 2010 at 14:18 - Comments
Bandirsen
Nice integration, thank you btw, how about creating a ZF-Doctrine 'integrator' forum, via IRC or google group maybe ?
19 July 10 at 23:57
The thing I believe is after ZF 2.0 comes out, I believe most of the current ZF - Doctrine integration ...
20 July 10 at 19:25

Compile APC for XAMPP on Snow Leopard

I’m using XAMPP as my local development environment on Snow Leopard. The XAMPP package does not include APC (Alternative PHP Cache). If we simply do a PECL install, you’ll find that PHP complains about the APC architecture. This happens because the XAMPP for OS X is 32 bit, and Snow Leopard is 64 bit, hence PECL builds a 64 bit apc.so.

To overcome this issue, we need to manually compile APC from source and here is how I did it.

First, download APC source from http://pecl.php.net/package/APC and double click on the tar file within finder will unzip it.

Then


cd ~/Downloads/APC-3.1.3p1/APC-3.1.3p1/
phpize
MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS="-arch i386 -g -Os  -pipe -no-cpp-precomp" CCFLAGS="-arch i386 -g -Os  -pipe" CXXFLAGS="-arch i386 -g -Os  -pipe" LDFLAGS="-arch i386 -bind_at_load" ./configure --enable-apc --with-apxs --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config-5.3.1
make
sudo cp modules/apc.so /Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626/.

We should see no errors and we should have the new APC so file copied into our PHP extension directory.

Next, enable APC from php.ini by adding the following 2 lines


extension=apc.so
apc.shm_size = 32

Now if you do php -m from command line, you’ll see APC listed as a loaded module.

Hope it helps and save you from pulling your hair out.

Reference

4 May 2010 at 15:34 - Comments

Integrate Zend_Tool with Netbeans 6.9 beta

I’ve recently read a lot about Zend Framework (Zend_Tool) integration with Netbeans. Today I decided to download the Netbeans 6.9 beta and setup everything on my local development machine (OS X).

Here is how I did it on OS X with XAMPP.

First, I included Zend Framework library via a PEAR repository hosted on Google Code.


sudo pear channel-discover zend.googlecode.com/svn
sudo pear install zend/zend

Completing the above will make Zend Framework available through PEAR, which should be in your PHP include_path.

Next, I downloaded and extracted the minimal Zend Framework package. Then I did


cd ~/Downloads/ZendFramework-1.10.3-minimal/bin
sudo cp zf.php /Applications/XAMPP/xamppfiles/bin/zf.php
sudo cp zf.sh /Applications/XAMPP/xamppfiles/bin/zf

After this, I can run zf from command line without having any errors. So … I did this


zf --setup storage-directory
zf --setup config-file

I can now download the latest Netbeans 6.9 beta and do the normal install. After installation, start up Netbeans, go to “Netbeans” -> “Preferences” from the menu bar. Navigate to the “PHP” -> “Zend” section. Enter “/Applications/XAMPP/xamppfiles/bin/zf” into the “Zend script” input box. Then click on “Register Provider” button.

Now Netbeans should have updated the zf config file, which I created by running the “zf –setup config-file” command. And at this stage, I can create Zend Framework based projects and run “zf” commands to manipulate my projects within Netbeans.

However, if I jump back to the terminal shell, I would notice the good old “zf” command is broken and complaining it cannot find a file called “NetBeansCommandsProvider.php”. Since I still want my terminal command line zf script working, I did this


sudo ln -s /Applications/NetBeans/NetBeans\ 6.9\ Beta.app/Contents/Resources/NetBeans/php/zend/NetBeansCommandsProvider.php /Applications/XAMPP/xamppfiles/lib/php/pear/NetBeansCommandsProvider.php

Now I am happy. Hope someone find it’s useful

27 April 2010 at 14:27 - Comments

Config phpUnderControl for ZF based applications

I recently reinstalled my MacBook Pro, and it proves that my earlier post on how to setup phpUnderCotnrol on Snow Leopard work well. I just followed the steps and phpUnderControl’s up and running again.

Now, I want to go into the details a bit to show the configurations I have done to use phpUnderControl to do continuos integration for my Zend Framework based applications. The testing application I used here is the ZFDoctrine12 project I’ve created. You could pull down the source code of it from my github project.

First, I create the necessary folder structure for a new phpUnderControl project, as well as the ant build file.

sudo mkdir /opt/cruisecontrol/projects/zfdoctrine12
sudo mkdir /opt/cruisecontrol/projects/zfdoctrine12/source
sudo mkdir /opt/cruisecontrol/projects/zfdoctrine12/build
sudo mkdir /opt/cruisecontrol/projects/zfdoctrine12/build/api
sudo mkdir /opt/cruisecontrol/projects/zfdoctrine12/build/coverage
sudo mkdir /opt/cruisecontrol/projects/zfdoctrine12/build/logs
sudo mkdir /opt/cruisecontrol/projects/zfdoctrine12/build/php-code-browser
sudo touch /opt/cruisecontrol/projects/zfdoctrine12/build.xml

Next, the ant build file content. You can see it’s fairly minimal, but you should get the idea and know how to beef it up

<?xml version="1.0" encoding="UTF-8"?>
<project name="zfdoctrine12" default="build" basedir=".">
  <target name="build" depends="php-codesniffer,phpunit"/>
  <target name="php-codesniffer">
    <exec executable="phpcs" dir="${basedir}/source" output="${basedir}/build/logs/checkstyle.xml" error="/var/tmp//checkstyle.error.log">
      <arg line="-n --report=checkstyle --standard=ZEND application"/>
    </exec>
  </target>
  <target name="phpunit">
    <exec executable="phpunit" dir="${basedir}/source/tests" failonerror="on">
      <arg line=" --log-junit ${basedir}/build/logs/phpunit.xml --coverage-clover ${basedir}/build/logs/phpunit.coverage.xml --coverage-html ${basedir}/build/coverage"/>
    </exec>
  </target>
</project>

Next, I want to clone the project from my local git repository into my phpUnderControl monitored project directory. To do this, we do

cd /opt/cruisecontrol/projects/zfdoctrine12/source/
sudo git clone ~/Sites/zfdoctrine12/ .

You can see that I’m only cloning the project from my local project repository, however this can be easily changed to utilise a remote git repository. e.g. repositories hosted on github.

I admit that after doing the git clone, I had to manually create and copy a couple of files. This was because of my .gitignore file from my local repository. So, go to the .gitignore file from your project repo, and do whatever changes that make sense to you.

Now, let’s setup the phpUnderControl config.xml file, to make phpUnderControl become aware of our newly created project. Add the following XML snippet to your /opt/cruisecontrol/config.xml.

  <project name="zfdoctrine12">
    <listeners>
      <currentbuildstatuslistener file="logs/${project.name}/status.txt"/>
    </listeners>
    <modificationset quietperiod="60">
      <git localWorkingCopy="projects/${project.name}/source/" />
    </modificationset>
    <bootstrappers>
      <gitbootstrapper localWorkingCopy="projects/${project.name}/source/" />
    </bootstrappers>
    <schedule interval="300">
      <ant anthome="apache-ant-1.7.0" buildfile="projects/${project.name}/build.xml"/>
    </schedule>
    <log dir="logs/${project.name}">
      <merge dir="projects/${project.name}/build/logs/"/>
    </log>
    <publishers>
      <artifactspublisher
        dir="projects/${project.name}/build/api"
        dest="artifacts/${project.name}"
        subdirectory="api"/>
      <artifactspublisher
        dir="projects/${project.name}/build/coverage"
        dest="artifacts/${project.name}"
        subdirectory="coverage"/>
      <execute
        command="phpcb
                --log projects/${project.name}/build/logs
                --source projects/${project.name}/source
                --output projects/${project.name}/build/php-code-browser"/>
      <artifactspublisher
        dir="projects/${project.name}/build/php-code-browser"
        dest="artifacts/${project.name}"
        subdirectory="php-code-browser"/>
      <execute command="/Applications/XAMPP/xamppfiles/bin/phpuc graph logs/${project.name} artifacts/${project.name}"/>
      <email
        buildresultsurl="http://localhost:8080/cruisecontrol/buildresults/zfdoctrine12"
        mailhost="smtp.gmail.com"
        mailport="465"
        usessl="true"
        username="USERNAME"
        password="PASSWORD"
        returnaddress="SENDER_EMAIL">
        <always address="RECIPIENT_EMAIL"/>
      </email>
    </publishers>
  </project>

The above project config tells CruiseControl to look for VCS (git in this case) changes, if any changes are detected, a build will be triggered every 5 min. The result is then emailed out to a nominated email address.

This is it. It should give you a start point, and then it’s up to you to tune it yourself. Hope it helps for people like myself, who is a beginner in Continuous Integration.

Reference

22 March 2010 at 11:35 - Comments

Day 1 of learning Symfony

Long weekend. I’ll try to keep it short.

I’m a Zend Framework devotee. However Symfony is always on my to-learn list. I’m finally motivated today to give it a crack. Not to deny, a potential job lead also plays an important part in this.

I just spent the last 2 hours to download the library via SVN, follow the “Practical symfony” guide to setup a project and everything. All pretty straight forward. I’m on “Day 5″ of the guide now. I’ll stop here and finish the “tech” part of the day with this post (before my wife goes mad at me …).

So, what do I think about Symfony?

People talk about the steep learning curve of studying Symfony, but I didn’t find it’s too hard to follow. I think this is because of 2 reasons. 1, I understand the MVC pattern pretty well from my Zend Framework projects. 2, Symfony has got heaps of similarity to Ruby on Rails and I have finished reading my RoR book at the start of the year.

I quite like the Symfony view helpers, the YAML style configurations, the out of the box modular approach and the command line generators.

If time allows, I’ll blog more about Symfony in the future. For the next a couple of weeks or so, I might have to do some C#.Net for my next project.

Reference

7 March 2010 at 15:51 - Comments
Hayden, yes. I think you are right. Symfony is a very good choice for developing web apps. The reason I ...
11 June 10 at 10:53
Yes symfony is a wonderful framework that I love for its command line power . I don't think there is ...
17 June 10 at 04:59

Modal window over flash objects

I’ve been working on a WordPress site for a client. All pretty straight forward stuff. Only special requirement from the client is to have a categorised file repository as a WordPress page, which allows users to download files. One of the categories needs to be protected. So users click on a file download link and see a modal window with a form. Fill in the details, download the file.

The issue surfaced when we replaced the site banner with a flash (this is of course IE specific …). The popup modal window slides behind the flash object. This turned out to be a common issue and the fix is simple.

<object classid="clsid:D27CDB6E...." width="1151" height="209" ... >
    .... you other flash params stuff ...
    <param name="wmode" value="transparent">
</object>

The “wmode” transparent is the key!

I’m using SimpleModal, a jQuery plugin modal library.

Reference

19 February 2010 at 19:44 - Comments

Zend Framework on shared host

I came across an article made by Rob Allen (author of Zend Framework in Action) today. It gives us a very nice solution on how to host a Zend Framework project on a shared host.

The issue with running Zend Framework based application on a shared host is that sometimes you simply do not have the luxury to have “public” as your document root.  When I say “public”, I refer to the web root created in Zend Framework (the directory that contains index.php). Sometimes, your FTP root is your document root. This means you are forced to dump all other Zend Framework folders inside the document root.

2 issues with that,

  1. Security, everything becomes exposed to the web.
  2. Ugly URL, you’ll end up with something like http://mydomain.com/public/

Rob’s post addressed this problem really well.

Reference

9 February 2010 at 22:09 - Comments

Netbeans debugger with Zend Framework

Are you sick of doing var dumps on browser screens or error logs when you need to debug some errors? Have you seen the .Net guys step through their code line by line to figure out what went wrong? With PHP, you can do the same. Here’s how I do it.

The IDE I use is Netbeans (6.8 on Mac). It’s shipped with a built-in debugger, which works with Xdebug.

So … we first need to make sure our PHP is running Xdebug instead of Zend. I have explained how I have Xdebug setup on my XAMPP stack on Mac from one of my previous posts, Setup phpUnderControl on Snow Leopard. We can verify whether Xdebug is setup properly by loading up our phpinfo page. We should see something like this (notice the last line prints Xdebug)

Now, let’s go to Netbeans. Netbeans out of the box listens on port 9000, which is the exact port number we set our Xdebug remote_port to in our previous step. This means if we are not running our application with mod_rewrite, we now should be able to set a breakpoint in our code, hit the debug icon, and have everything going.

But … there’s always a but. When we develop Zend Framework based applications, in fact any applications that utilising mod_rewrite. We will run into trouble. We’ll find the debugger always hits the index controller, index action. To overcome this, we need to do the following.

Go to the Zend Framework application’s project property in Netbeans. Go to the “Run Configuration” option. Click on Advanced. For “Debug URL”, choose “Ask Every Time”.

Now, if we want to debug the email action from the index controller, when we hit the debug icon in Netbeans, it’ll pop up a dialog box asking us to type in the debug URL.

Once we Ok the dialog, Firefox will fire up (after you install the Netbeans debugger), and off you go!

The screenshots above are grabbed from my ZFWithDoctrine project on github.

That’s it, and hope it helps.

8 February 2010 at 20:28 - Comments
undertruck
Perfect. This solved my problem. Thanks.
9 February 10 at 17:40
@undertruck glad to know you have your issue resolved
9 February 10 at 19:23

File include cache in Zend Framework

Another box of tissue gone … runny nose syndrome continues … still cannot type or think …

Let me now blog something simple, but handy.

Problem … Zend Framework uses many types of plugins, how do we efficiently tell the application where to find the plugin files? For example, when we use a view helper, should our application find it in the Zend library directory? Should our application find it in the application view helpers directory? Or should the application find it at our own custom library directory?

Fix … it’s easy.

Make the following extra line of config in your application config file

cache.classFileIncludeCache   = APPLICATION_PATH "/../data/pluginLoaderCache.php"

Add the following code to your Bootstrap.php

  /**
     * Setup include file cache to increase performance
     *
     * @return void
     * @author Jim Li
     */
    protected function _initFileInlcudeCache()
    {
        $classFileIncCacheOptions = $this->getOption('cache');
        $classFileIncCache = $classFileIncCacheOptions['classFileIncludeCache'];

        if(file_exists($classFileIncCache)) {
            include_once $classFileIncCache;
        }
        Zend_Loader_PluginLoader::setIncludeFileCache($classFileIncCache);
    }

Attention: make sure the “/data/” directory is writable by your web server.

Reference

7 February 2010 at 13:12 - Comments