Ants in my Zend Framework (with doctrine for good measure)

July 15th, 2009

I’m starting to use Zend Framework 1.8.4 with Doctrine Object Relational Mapper (because after working on a java/hibernate project, I can’t go back to writing SQL and building databases)  With Doctrine ORM, you can define a data model in YAML or XML and it will build the database with foreign keys, etc, etc ,etc… learn more on that here.

On starting my project, I looked around to see what everyone else was doing.  Since 1.8.4 is relatively new, and there were some pretty neat changes, there aren’t many good tutorials out there.

That being said, and because of said java/hibernate project I’ve been working on, I’ve become quite familiar with Apache Ant.  It’s basically an easy way to do some of the mundane work and sometimes heavy lifting in day to day programming.  That, and I use Eclipse IDE, so wasn’t too fond of always running to the command prompt to rebuild my models, create a zend module, etc.

So here’s what I’ve come up with.

I started with this tutorial: Doctrine ORM and Zend Framework It shows you how to create a Zend 1.8.4 project with doctrine.  The key aspect is the doctrine-cli.php script.

I should let you know, while I do use Eclipse for most of my projects, a while back I bought Zend Studio for Eclipse. I think it’s much better for writing PHP than any plugin for eclipse (PDT, PHPEclipse).  If you write a lot of PHP, ZS4E is very very worth the money.  While it does say it is “zend studio for eclipse”, it installs its own installation of eclipse.  If you find yourself in this boat, and want to use Ant in Zend Studio for Eclipse, check out this tutorial.  It’s rather screwy that you can’t install ant tools easily, but this definitely does the trick.

But I digress… let’s get started.

Here is the directory structure of my project, basically defined by the above tutorial:

- root
-  htdocs [zend framework project root]
    - application
        - [all application folders]
        - doctrine
    - library
    - public
    - scripts
    - test
-  .project
-  build.xml
-  env.properties

The body of env.properties looks like this:

zf.project.basedir=htdocs
doctrine.scripts.path=${zf.project.basedir}/scripts

And the body of the build.xml looks like this:

<project name="zf-doctrine-project">
     <property file="env.properties" />
     <target name="doctrine.cli" description="Run a doctrine task on doctrine-cli.php - default reload">
          <input message="Enter a task:"
               addproperty="doctrine.task"
               defaultvalue="build-all-reload" />
          <fail unless="doctrine.task" message="No task selected" />
          <exec dir="${doctrine.scripts.path}"
               command="php doctrine-cli.php ${doctrine.task} y"/>
     </target>
</project>

Although it’s painfully self-explanatory, for the sake of completeness, here’s what it does, line by line:

2.  Loads in the env.properties file
3.  Defines the target, which is like a job/task in ant
4. – 6.  Prompts the user to enter a task to pass to the cli script (just like you would pass in the command line)
7.  Makes sure the user enters a value
8. – 9. Executes the php script, passing in the entered task as a command line option, and forces yes to “are you sure?”

Now, the fun part.

In your project in Eclipse, open the ant window by going to Window > Show View > Other and select Ant under the Ant folder.  When you see the Ant View, either open your ant file in that window using it’s open dialog, or just drag your build.xml to that panel.  You’ll see the little white file with the ant on it and whatever you have as the name attribute of the <project> tag in your build xml.  Expand that so you can see the targets, and you should see this:

Showing the doctrine task in the eclipse ant view

Showing the doctrine task in the eclipse ant view

Now if you double click that target, you should see a prompt for the task you want to run.  The default value there will run your schema.yml and rebuild your db and models.

Crafty kids may notice that i have the “Hide internal targets button” turned on in that image… well, those targets are for another show…  (damn you crafty kids…)

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Granite SecureAMFChannel – AMF over HTTPS

March 15th, 2009

At work we’ve started to use JBoss, writing an application in Java and AS 3.0.  We’re using Seam and Tide to sandwich it all together, and we came upon a slight problem.  Everything worked out great in the test environment, but when we went live, on an HTTPS connection, firebug was reporting that the AMF request out of flex was failing.  That’s due to the services-config.xml in the application pointing to a non-secure connection.  After much digging, we found this to be the solution.

WEB-INF/flex/services-config.xml
in the channels definition at the top:

<channels>
    <!--USED IN THE LIVE ENVIRONMENT-->
          <!--channel ref="my-graniteamf-secure"/-->
    <!--USED IN THE LOCAL/DEV ENVIRONMENT-->
          <channel ref="my-graniteamf"/>
</channels>

Then in the channel definition below we have both definitions:

<channel-definition id="my-graniteamf"
	class="mx.messaging.channels.AMFChannel">
	<endpoint
		uri="http://{server.name}:{server.port}/{context.root}/graniteamf/amf"
		class="flex.messaging.endpoints.AMFEndpoint" />
</channel-definition>
<channel-definition id="my-graniteamf-secure"
	class="mx.messaging.channels.SecureAMFChannel">
	<endpoint
		uri="https://{server.name}:443/{context.root}/graniteamf/amf"
		class="flex.messaging.endpoints.SecureAMFEndpoint" />
</channel-definition>

Click Here to Download: services-config.xml

We couldn’t get {server.port} to work correctly, so we’re forcing the port in the address for now.

The only problem with this is you have to remember to switch the AMF channel before deploying.  It’s on our checklist before doing the full deploy, but we’re most likely going to add it to the ant task list to deploy dev, deploy live.  Something like that.

The KEY THING TO REMEMBER is this: although this file is deployed with the war/ear, it is ALSO COMPILED INTO THE APPLICATION SWF when it is built.  Make sure to change it locally and rebuild your swf before posting, or you will see no change in your app. (found this out after a significant amount of time changing the file on the server to no avail…)

(Ref: http://www.mail-archive.com/discussion@affug.com/msg00605.html)
[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Still Alive… Car? Not so much.

December 29th, 2008
It's just a little smashy, it's still good, it's still good!

It's just a little smashy, it's still good, it's still good!

This weekend, coming home from my parents for Christmas, I was involved in a little smash-up.  Roads were a little wet, traffic was tight and rather slow moving, and I was travelling down a slight decline just north-east of the Palisades Mall in New York on 287.  Abruptly (as most accidents seem to happen) everyone decided it’d be fun to stop as fast as possible.  I slammed on my brakes and slid my Nissan Altima into a Mazda 626.  Apparently I wasn’t the only one surprised, however, as there were 3 other identical accidents around me.

Mmmmm... Crash-tastic!

Mmmmm... Crash-tastic!

Shaken, but still in one piece, the other driver and I pulled to the side, as did the other unfortunate people.  We got out, made sure everyone was ok, and assessed the damage.  Her car may have added a scratch to it’s already impressive collection, but mine was a little worse for wear.  As it was my fault, she said it’s up to me if we want to get the insurance companies involved, but right as that question arose, a very friendly police officer rode up and asked for our paperwork.  He was probably sent to the scene because one of the other accident groups were screaming all irate-like and most likely reported all the accidents in the vicinity to 911.

This was the nicest, most helpful police officer I’ve ever seen in one of these situations.  He made sure we were ok, asked for our paperwork, and in about 5 min, presented us with a printout detailing each others information and sent us on our way.  I expected an impatient, slightly-condescending cop to hand me a ticket for some reason, but not this time.  This made the experience a little less aggravating.

So, hats off to the Tarrytown Police K9 unit!

Anyway, being in situations like this really makes you think…  After driving for almost 10 years or so without an accident (just a slight fender bender about a year after I got my license) it really makes you second-guess those “well, I’ll just send them a text message while I’m going 80mph” or “sure, I can eat this taco while driving..”  I was concentrating on driving because of the traffic and the road conditions and I got into an accident that may actually end with my car being totaled (it’s not really worth fixing a ‘99 Altima if there’s anything other than cosmetic damage).

Also, so far, I’m happy with Geico.  They’ve been very helpful and I’m only responsible for my deductable (as expected).  But I’ll be sure to post if anything of note happens.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

sproif.com is Digg proof thanks to caching by WP Super Cache!