Using Oracle Driver with Zend Framework

Spent far too much time fiddling around with configuration options to get this to work.

In your application.ini file, you will need something that looks like this.

  1. resources.db.adapter = Oracle
  2. resources.db.params.username = myusername       
  3. resources.db.params.password = mypassword
  4. resources.db.params.dbname = my.host.name.com:portnumber/mydbinstance

notice that you don’t need a “resources.db.paramas.host” line here. The “mydbinstance” part comes from your tnsnames.ora file…

  1. mydbinstance =
  2.   (DESCRIPTION =
  3.     (ADDRESS = (PROTOCOL = TCP)(HOST = my.host.name.com)(PORT = 1771))
  4.     (CONNECT_DATA =
  5.       (SERVER = DEDICATED)
  6.       (SERVICE_NAME = mydbinstance)
  7.     )
  8.   )

Hope this saves someone some time!

Configuring vhosts and fixing zf.exe tool with initial setup of Zend Server CE and Zend Framework 1.9.1 on Windows.

I’ve just spent a few hours wading through what should otherwise be simple.

First of all, download Zend Server CE you can get it here:

http://www.zend.com/en/products/server-ce/downloads

I chose the PHP 5.3 version.

Start the install, and choose custom install if you want to also install MySQL Server and PhpMyAdmin.

Once the install is complete, you would think that you would be ready to go…Should be simple…Zend Framework on running Zend Server. Not so!

First of all, at the time of this writing, Zend Framework 1.9.0 and 1.9.1 have a bug which makes it impossible to use the command line tool to do anything other than create a project on a windows system. If you are installing on Windows, you will need to manually add a few lines to the

Zend/Tool/Project/Provider/Abstract.php

file. This is a pain, but I’m sure it will be fixed soon.

You can get all the details the fix for it here:

http://zendframework.com/issues/browse/ZF-7465

I used the second fix, and it works fine. If you don’t patch this, you will get an error when you try to create a module after you’ve created your project, and you will probably tear your hair out finding the problems.

Next, once you patch, and create a project, you would think that it would be easy to create a virtual host for your new project. After unsuccessfully trying many different snippets of advice, I finally came across this, buried in the “best practices” part of the installation guide here:

http://files.zend.com/help/Zend-Server-Community-Edition/configuring_zend_framework.htm

First, assuming that you created your project in the web root of your new installation, and your project is called “yourprojectname” you would cut and paste the following text directly into the very bottom of your

C:\Program Files\Zend\Apache2\conf\http.conf

file. I’m not sure why this is considered a best practice (as opposed to using /extra/httpd-vhost.conf file), but it works.

  1. Listen 84
  2.  
  3. <VirtualHost *:84>
  4.  
  5.     DocumentRoot "C:\Program Files\Zend\Apache2\htdocs\yourprojectname\public"
  6.  
  7.     <Directory "C:\Program Files\Zend\Apache2\htdocs\yourprojectname\public">
  8.  
  9.         Order allow,deny
  10.  
  11.         Allow from all
  12.  
  13.     AllowOverride all
  14.  
  15. </Directory>
  16.  
  17. </VirtualHost>

Now your new project will be served on http://localhost:84/

Next, you need to have an .htaccess file in the \public directory of the new project you just created. So if the module you created was “mynewmodule”, you would create a file called .htaccess in

C:\Program Files\Zend\Apache2\htdocs\mynewproject\public

If there is already contents in that file, you should comment out existing code first, then past this below:

# public/.htaccess

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -s [OR]

RewriteCond %{REQUEST_FILENAME} -l [OR]

RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ – [NC,L]

RewriteRule ^.*$ /index.php [NC,L]

Whew! That’s it!

Remember to restart your apache server, you should now see your zend framework homepage at http://localhost:84/

You should be able to get started coding now!

Dead Simple as3flickr, Flickr API Example

I’ve finally had a chance to start messing around with the ActionScript 3 Flickr API, as3flickr. One thing I noted right away is that there aren’t too many dead simple examples of how to use the library. Most of the examples out there dive right into authentication, which isn’t a good place for the newbie to start as it isn’t required for many applictions.

A better place to start, in my option, is to just get a set of photos, and return data about the photos. Extremely useful, dead simple. Here goes.

  1. public static var FLICKR_API_KEY:String         = "whatever your api string is";
  2. public static var FLICKR_API_SECRET:String      = "whatever your api secret is";
  3.  
  4. public var flickrService:FlickrService = new FlickrService(FLICKR_API_KEY);
  5.  
  6.  
  7. private function startFlickr():void
  8. {
  9.        
  10.         flickrService.secret = FLICKR_API_SECRET;
  11.         flickrService.addEventListener( FlickrResultEvent.PHOTOSETS_GET_PHOTOS, onPhotosetGetPhotos);
  12.         flickrService.photosets.getPhotos(‘a set id number goes here’);
  13.        
  14. }
  15.  
  16. private function onPhotosetGetPhotos (event:FlickrResultEvent):void
  17. {
  18.         var photoSet:PhotoSet = event.data.photoSet;   
  19.         photos = new ArrayCollection (photoSet.photos);
  20.  
  21.         for each (var p:Photo in photos)
  22.         {
  23.                 trace(p.title);
  24.                 trace(p.id);
  25.         }
  26. }

using the parent() function in e4x epressions and actionscript to create complex queries.

Let’s say you have the following xml for greeting cards.

  1. <designlist>
  2. <design
  3.  id="123"
  4. title="Happy Hanukkah"
  5. previewImageUrl="assets/demo/images/g0022_4×6h_preview.jpg"
  6. thumbImageUrl=""
  7.    <tags>
  8.   <tag id=‘1231′></tag>
  9. <tag id=‘3242′&gt;Hanukkah&lt;/tag&gt;</code></blockquote>
  10. </tags>
  11. <code> &lt;/design&gt;</code>
  12. <p align="left">&nbsp;</p>
  13.  
  14. <p align="left"><code>&lt;design
  15. </code>
  16. <blockquote><code> id="456"</code>
  17. <code> title="Happy New Year"</code>
  18. <code> previewImageUrl="assets/demo/images/g0412_4×6h_preview.jpg"</code>
  19. <code> thumbImageUrl=""&gt;</code>
  20. <code> &lt;tags&gt;</code>
  21. <blockquote><code> &lt;tag id=’1231′&gt;Holiday&lt;/tag&gt;</code>
  22. <code> &lt;tag id=’2342′&gt;New Year&lt;/tag&gt;</code></blockquote>
  23. <code> &lt;/tags&gt;</code>
  24. <code></code></blockquote>
  25. <p align="left"><code> &lt;/design&gt;</code></p>
  26. <p align="left">&nbsp;</p>
  27.  
  28. <p align="left"><code>&lt;design
  29. </code>
  30. <blockquote><code> id="8284"</code>
  31. <code> title="Merry Xmas"</code>
  32. <code> previewImageUrl="assets/demo/images/g0256_4×6v_preview.jpg"</code>
  33. <code> thumbImageUrl=""&gt;</code>
  34. <code></code></blockquote>
  35. <blockquote><code> &lt;tags&gt;</code>
  36. <blockquote><code> &lt;tag id=’1231′&gt;Holiday&lt;/tag&gt;</code>
  37. <code> &lt;tag id=’3242′&gt;XMas&lt;/tag&gt;</code>
  38. <code> &lt;tag id=’8323′&gt;Christmas&lt;/tag&gt;</code></blockquote>
  39. <code> &lt;/tags&gt;</code>
  40. <code></code></blockquote>
  41. <p align="left"><code> &lt;/design&gt;</code></p>
  42. <p align="left">&nbsp;</p>
  43.  
  44. <p align="left"><code>&lt;design
  45. </code>
  46. <blockquote><code> id="8284"</code>
  47. <code> title="Happy Happy Happy"</code>
  48. <code> previewImageUrl="assets/demo/images/g0055_4×6v_preview.jpg"</code>
  49. <code> thumbImageUrl=""&gt;</code>
  50. <code></code></blockquote>
  51. <blockquote><code> &lt;tags&gt;</code>
  52. <blockquote><code> &lt;tag id=’1231′&gt;Holiday&lt;/tag&gt;</code>
  53. <code> &lt;tag id=’3242′&gt;Happy&lt;/tag&gt;</code>
  54. <code> &lt;tag id=’3242′&gt;Wonderful&lt;/tag&gt;</code></blockquote>
  55. <code> &lt;/tags&gt;</code>
  56. <code></code></blockquote>
  57. <p align="left"><code> &lt;/design&gt;</code></p>
  58. </blockquote>
  59. <code>&lt;/designlist&gt;</code>
  60.  
  61. <code>&lt;/design&gt;</code>

And let’s say we wanted to return the titles for designs for that are tagged with “New Year”. This is tricky because the tags are further down the XML tree than the title, which is an attribute of the design itself.  How would we express this in e4x and actionscript?

var titles:XMLList = designViewerPanel.designListXml.design.@title.(parent().design.tags.(tag==”New Year”));

The key here is to use the parent() function, which returns us back to the top level of the xml tree. We can then express the particular tag we are looking for.

I still haven’t figured out how to do the same expression with out specifying the designs.tags…in other words, I’d like to say something like

(parent()..(tag==”New Year”))

but when I try this I get an error…actionscript doesn’t seem to like the parenthesis next to ‘tag’. Ideas anyone?

Changing the default setting for del.icio.us bookmarks app to Do Not Share

When I tag a page using del.icio.us, I always have to click “do not share” if I don’t want the link showing up on facebook and elsewhere. Annoying!

This can be changed.

Open firefox. Type in

about:config

into the address bar. Right click anywhere on the page. From the menu that appears, select New->Interger.

It will ask for a name of the new preference. Enter:

extensions.ybookmarks@yahoo.sharemode

It will ask for a value next. Type

1

That’s it! Now the delicious app will default to having the “Do Not Share” option selected. I really wish they made this more straight forward.

Subversion integration with Active Reload’s wonderful Lighthouse Issue Tracking site.

I realize this post is probably not as interesting as integrating Lighthouseapp with GIT but I thought I would jot down a couple of notes.

There is a great script that shows you how to set up subversion with lighthouse here:

http://www.lighthouseapp.com/help/setting-up-subversion-integration

The documentation is sufficient, but too sparse for my tastes.

Here’s some notes that might help you.

1. First of all, you’ll need to know where your subversion repository is stored on your server. Let’s say its in: /svn/repos

2. In that folder there should be another folder called “hooks”. You’ll need to create a file called “post-commit” in this directory, if there isn’t one already. In that empty file put the following:

#!/bin/sh
REPOS=”$1″
REV=”$2″
/svn/repos/hooks/lighthouse.rb “$REPOS” “$REV”

4. Next, copy the script from the link at the top of this page to a file called “lighthouse.rb” in the /svn/repos/hooks/ directory. You’ll need to change a few things in this file. You’ll need to set the token to the api token you created on lighthouseapp. I’m not entirely sure what the seperate user tokens that follow that are for…ours seems to work fine without each user having their own token. “Account” is the the base url of your lighthouseapp page. Should be something like ‘http://mycompany.lighthouseapp.com’. The project number, which the author claims is self expanatory, is the number that you find in the URL when you are looking at a particular issue. For instance, your URL might look like this:

http://mycompany.lighthouseapp.com/projects/8958-launch/overview

You want the 8958 from here…you don’t want to include the “-launch” part. I disabled the “prefix:” option by deleting this line completely, and removing the comma from the previous line.

5. Finally, you have to make sure that your permissions on your post-commit and your lighthouse.rb file are executable. To test, you could do a chmod 777 lighthouse.rb and chmod 777 post-commit. You’ll want to set these more strictly once you have your server set up.

6. That’s it. You should be able to run

./post-commit /svn/repos 200

from your hooks directory (200 is the number of an existing revision in your subversion repository), and it should run. On lighthouse, you should see a new entry that says “changeset” with information about the revision, and who made it. Any new commits with now show up in lighthouse as well.

picture-3.png

creating control arrays with qcodo

Lately I’ve been playing around with the qcodo framework. There’s a lot of things to love about qcodo, but the 4 or 5 lines of code required to put together a single control is not one of them.

For instance, if I wanted to create a text box on a page. I could something like this.

class MyCoolPage extends QForm {
protected $txtYourNameGoesHere;
function Form_Create{
$txtYourNameGoesHere = new QLabel($this);
$txtYourNameGoesHere->Name = “NameBox”;
$txtYourNameGoesHere->Text = “Write your name here”;
$txtYourNameGoesHere->Width = 100;
$txtYourNameGoesHere->CssClass = “name-box”;
$txtYourNameGoesHere->Required = TRUE;
}
}

If you just have one or two controls on a page, this is not big deal, but if you have a full page of text boxes and labels this gets unwieldy quickly. One solution for this is to first create an array with details about all the controls you’d like to have on your pages, then create a second control array that contains all of your controls. For instance, you can do something like this:

protected $arrListOfControls = Array();
protected $arrControls = Array();
function Form_Create() {
$arrListOfControls = Array(
‘BillName’ => Array(’Name’ => ‘BillName’, ‘Text’=>’Default Name’, ‘Width’ => 100, ‘Required’ => false, ‘Type’ => ‘Label’, ‘CssClass’=>’addressee’),
‘BillAddress1′ => Array(’Name’ => ‘BillAddress1′, ‘Text’=>’default Address1′, ‘Width’ => 100, ‘Required’ => false, ‘Type’ => ‘Label’, ‘CssClass’=>’street-address’),
‘BillAddress2′ => Array(’Name’ => ‘BillAddress2′, ‘Text’=>’default Address2′, ‘Width’ => 100, ‘Required’ => false, ‘Type’ => ‘Label’, ‘CssClass’=>’street-address’),
‘BillCity’ => Array(’Name’ => ‘BillCity’, ‘Text’=>’default City’, ‘Width’ => 100, ‘Required’ => false, ‘Type’ => ‘Label’, ‘CssClass’=>’locality’),
‘BillZip’ => Array(’Name’ => ‘BillZip’, ‘Text’=>’99999′, ‘Width’ => 100, ‘Required’ => false, ‘Type’ => ‘Label’, ‘CssClass’=>’postal-code’),
‘BillState’ => Array(’Name’ => ‘BillState’, ‘Text’=>’ST’, ‘Width’ => 100, ‘Required’ => false, ‘Type’ => ‘Label’, ‘CssClass’=>’region’),
‘BillPhone’ => Array(’Name’ => ‘BillPhone’, ‘Text’=>’123-452-4444′, ‘Width’ => 100, ‘Required’ => false, ‘Type’ => ‘Label’, ‘CssClass’=>’country-name’),
‘ShipName’ => Array(’Name’ => ‘ShipName’, ‘Text’=>’Default Name’, ‘Width’ => 100, ‘Required’ => false, ‘Type’ => ‘Label’, ‘CssClass’=>’addressee’),
‘ShipAddress1′ => Array(’Name’ => ‘ShipAddress1′, ‘Text’=>’default Address1′, ‘Width’ => 100, ‘Required’ => false, ‘Type’ => ‘Label’, ‘CssClass’=>’street-address’),
‘ShipAddress2′ => Array(’Name’ => ‘ShipAddress2′, ‘Text’=>’default Address2′, ‘Width’ => 100, ‘Required’ => false, ‘Type’ => ‘Label’, ‘CssClass’=>’street-address’),
‘ShipCity’ => Array(’Name’ => ‘ShipCity’, ‘Text’=>’default City’, ‘Width’ => 100, ‘Required’ => false, ‘Type’ => ‘Label’, ‘CssClass’=>’locality’),
‘ShipZip’ => Array(’Name’ => ‘ShipZip’, ‘Text’=>’99998′, ‘Width’ => 100, ‘Required’ => false, ‘Type’ => ‘Label’, ‘CssClass’=>’postal-code’),
‘ShipState’ => Array(’Name’ => ‘ShipState’, ‘Text’=>’TS’, ‘Width’ => 100, ‘Required’ => false, ‘Type’ => ‘Label’, ‘CssClass’=>’region’),
‘ShipPhone’ => Array(’Name’ => ‘ShipPhone’, ‘Text’=>’777-777-7777′, ‘Width’ => 100, ‘Required’ => false, ‘Type’ => ‘Label’, ‘CssClass’=>’country-name’)
foreach ($arrListOfControls as $ctlname => $properties) {
buildTextBoxes ( $arrControls[$ctlname] );
}
}
function buildTextBoxes(&$ctl , array $properties) {
$ctl = new QTextBox($this, $properties['Name']);
$ctl->CssClass = $properties['CssClass'];
$ctl->Width = $properties['Width'];
$ctl->Text = $properties['Text'];
$ctl->BlahBlahBlah = $properties['BlahBlahBlah'];
}

Notice two things of importance here…in the buildTextBoxes function, there is an ampersand…this informs php to pass the whole variable, instead of just the value of the variable. When the function is complete, the new control object dressed up in the properties you provided. Another thing to note is when we create the QTextBox, we specifiy a name for the control. This is important to distinguish the contols in your html source when you view them page…it makes formatting your template easier!

what is this all about?

So I’ve been wanting, for some time now, to put together a blog, the sole purpose of which is to record my geeky finds from around the internet. Others have saved me countless hours by posting their solutions, I just want to give something back.

My plan here is to not waste a lot of time customizing this site; I spent 10 minutes getting this blog in place and I don’t want to spend any more time. I don’t want a headache when I go to upgrade to the next version of wordpress.

This blog is all about keeping it simple and saving time.

So there you have it, the stock theme,  plaintxtBlog, by Scott Allan Wallick. Thanks Scott!