Zend Studio – Shift-Tab Functionality – Not Working!

I just did a fresh install of Zend Studio and become frustrated when now Shift-Tab wasn’t pushing my code to the left as it should! I looked online for a solution and thankfully someone else had the problem and found a working solution! Below is entry from the user:

I got the same problem and I believe I found a way to fix it.

By changing the PHP code formatter from "PHP conventions" to "Zend Framework Convention" it seems to work. (You have to close and reopen the file you were editing to apply the change) This is in Preferences > PHP > Code Style > Formatter. Thanks to davidjam for the pointer.

I guess there is some setting in the PHP convention that creates this annoying behavior, but I don't know what it is exactly.
Friday, May 21st, 2010 Uncategorized No Comments

Disable the View/Layout in Zend Framework

Use the following snippet to disable the view/layout in the Zend Framework:

class IndexController extends Zend_Controller_Action
    public function init()
        // Disable render helper and zend Layout
Monday, April 26th, 2010 Zend Framework No Comments

jQuery Floating Table Header Plugin

Ever have a really long table and want the table header to follow you down the screen as you scrolled? I guess someone else has too… This plug-in came in very handy and works great!


Thursday, April 22nd, 2010 jQuery 1 Comment

RegEx / Regular Expression for filename and file extension

This is a helpful snippet that I have found myself searching for in the google machine. Hopefully this helps you out!

$filename = "thisismyfilename.ext";

preg_match("/(.*)\.([^\.]+)$/", $filename,  $matches);



Wednesday, April 7th, 2010 PHP No Comments

Finding the Week of the Month using MySQL

Recently for a project I needed to be able to query when something was at least a day old and wanted to make sure that I updated the item every month on the first wednesday. I wanted to utilize mysql to query those that I needed and was able to find another blog’s entry on how to do that – the following is the code needed to retrieve the day of the week for the specified date:

SELECT WEEK(my_date_field,5) -
WEEK(DATE_SUB(my_date_field, INTERVAL DAYOFMONTH(my_date_field)-1 DAY),5)+1

Thanks go to:


Tuesday, March 2nd, 2010 MySQL No Comments

Implementing PayPal’s NVP API to send Mass Payments

Recently I was involved in a project where we needed to send payments to customers for different services. I decided to implement PayPal MassPay in order to submit these payments through an interface. The following code will give you all the code you need to send payments through the PayPal NVP API.

Post any questions!

// Use this class to construct the NVP calls to the paypal service

class PayPal_CallerService {

    public $API_UserName;
    public $API_Password;
    public $API_Signature;
    public $API_Endpoint;
    public $last_request;
    public $last_response;
    public $version;
    public $subject;
    public function __construct($credentials)
        if(is_array($credentials)) {
            $this->API_UserName  = (isset($credentials['API_USERNAME'])  && !empty($credentials['API_USERNAME']))  ? $credentials['API_USERNAME'] : '';
            $this->API_Password  = (isset($credentials['API_PASSWORD'])  && !empty($credentials['API_PASSWORD']))  ? $credentials['API_PASSWORD'] : '';
            $this->API_Signature = (isset($credentials['API_SIGNATURE']) && !empty($credentials['API_SIGNATURE'])) ? $credentials['API_SIGNATURE'] : '';
            $this->API_Endpoint  = (isset($credentials['API_ENDPOINT'])  && !empty($credentials['API_ENDPOINT']))  ? $credentials['API_ENDPOINT'] : 'https://api-3t.sandbox.paypal.com/nvp';
            $this->version       = (isset($credentials['VERSION'])       && !empty($credentials['VERSION']))       ? $credentials['VERSION'] : '60.0';
            $this->subject       = (isset($credentials['SUBJECT'])       && !empty($credentials['SUBJECT']))       ? $credentials['SUBJECT'] : '';
        } else {
            throw new Exception('You must pass in an array of credentials to instantiate this class.');
    public function callPayPal($methodName,$base_call = NULL)
        $header_call = "&PWD=".urlencode($this->API_Password).
        $call = $header_call.$base_call;
        //setting the curl parameters.
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$this->API_Endpoint);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        //Turning off the server and peer verification(TrustManager Concept).
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_POST, 1);
        //If USE_PROXY constant set to TRUE in Constants.php, then only proxy will be enabled.
        //Set proxy name to PROXY_HOST and port number to PROXY_PORT in constants.php 
            curl_setopt ($ch, CURLOPT_PROXY, PROXY_HOST.":".PROXY_PORT);*/ 
        //Check if version is included in $nvpStr else include the version.
        if(strlen(str_replace('VERSION=', '', strtoupper($call))) == strlen($call)) {
            $nvpStr = "&VERSION=" . urlencode($this->version) . $call;	
        $this->last_request = $nvpreq;
        //Setting the nvpreq as POST FIELD to curl
        //Getting response from server
        $response = curl_exec($ch);
        //Converting NVPResponse to an Associative Array
        $nvpResArray = $this->deformatNVP($response);
        $nvpReqArray = $this->deformatNVP($nvpreq);
        $_SESSION['nvpReqArray'] = $nvpReqArray;
        if (curl_errno($ch)) {
            throw new Exception('Curl error: '.curl_errno($ch).' - '.curl_error($ch));
         } else {
        	//Closing the curl
         $this->last_response = $nvpResArray;
        return $nvpResArray;
     * This function will take NVPString and convert it to an Associative Array and it will decode the response.
      * It is usefull to search for a particular key and displaying arrays.
      * @nvpstr is NVPString.
      * @nvpArray is Associative Array.
    public static function deformatNVP($nvpstr)
     	$nvpArray = array();
    		//postion of Key
    		$keypos= strpos($nvpstr,'=');
    		//position of value
    		$valuepos = strpos($nvpstr,'&') ? strpos($nvpstr,'&'): strlen($nvpstr);
    		/*getting the Key and Value values and storing in a Associative Array*/
    		//decoding the respose
    		$nvpArray[urldecode($keyval)] = urldecode( $valval);
    		$nvpstr = substr($nvpstr,$valuepos+1,strlen($nvpstr));
    	return $nvpArray;

The following is a script used to instantiate the PayPal class and send a mass payment.

                $credentials['API_USERNAME']  = 'username';
                $credentials['API_PASSWORD']  = 'password';
                $credentials['API_SIGNATURE'] = 'signature';
                $credentials['API_ENDPOINT']  = 'https://api-3t.sandbox.paypal.com/nvp';

                $amount  = urlencode($_POST['Amount']);
                $id          = urlencode(123456);
                $note      = urlencode('This is a note that will show up in the email.');
                $subject  = urlencode("Payment from Routy Design");
                $type      = urlencode('EmailAddress');
                $currency = urlencode($_POST['Currency']);
                $customer_email = urlencode($_POST['EmailAddress']);
                $base_call  = "&L_EMAIL0=".$customer_email.
                $PayPal = new PayPal_CallerService($credentials);
                $status  = $PayPal->callPayPal("MassPay", $base_call);

                //Do something if it is successfully sent
                if($status) {
                    if($status['ACK'] == "Success") {

                        //Check the balance of the account that was just debited, and make sure we have at least $500 left in our account
                        $balance = $PayPal->callPayPal("GetBalance", '');
                        if($balance['L_AMT0'] < 500) {
                            $message = "The balance is low... Please replenish the funds... \n\n".$balance['L_AMT0']." ".$balance['L_CURRENCYCODE0'];
                            mail('notifysomeone@routydesign.com','PayPal Refund Balance Low',$message);
                    } else if($status['ACK'] == "Failure"){
                        if($status['L_ERRORCODE0'] == '10321') {
                            $error = "Insufficient Funds to Send Refund to: ".$_POST['FirstName'].' '.$_POST['LastName'].'('.$_POST['EmailAddress'].') via PayPal in the amount of: '.$_POST['Amount'].' '.$_POST['Currency'].'. ';
                        } else if($status['L_ERRORCODE0'] == '10004') {
                            $this->view->error = "Invalid Amount of Refund to: ".$_POST['FirstName'].' '.$_POST['LastName'].'('.$_POST['EmailAddress'].') via PayPal in the amount of: '.$_POST['Amount'].' '.$_POST['Currency'].'. Must be more than 0 '.$_POST['Currency'].'.';
                        } else {
                            $this->view->error = "There was an unknown error when attempting to submit the payment.";

It is important to also setup a script to receive updates from PayPal via IPN’s (Instant Payment Notification).

Basically it’s a web address you give to paypal (http://blog.routydesign.com/paypal_ipn_updates.php) that they will send status updates to of the payments that are sent through their API. It is a way for your backend to keep tabs on what is happening with the payments to others. They send you an NVP formated string as a POST – all the variable they send in the post can be studied in their documentation, check the link below.

View their IPN PDF:

Tuesday, January 26th, 2010 API Services 2 Comments

SOAP Authenticatation using Soap Headers – API Class, Client, Server & WSDL Generation Examples

So about a week ago I needed to put together a SOAP service and wanted to make sure that not just anyone would be able to access the services. So I set about and scanned many pages in my google searches and have finally come to a working example. Hopefully you will find this page relatively quickly and save yourself the same nearly endless searches.

First let’s go ahead and create the server side of the service. I have posted the example of this code earlier on in another SOAP tutorial, but I will go ahead and throw it in here as well.
› Continue reading

Tuesday, January 5th, 2010 API Services, Zend Framework 5 Comments

Auto-Generating a SOAP WSDL using the Zend Framework

WSDL’s are not fun to make by hand. If you have to make a change or add a function, the slowest part would be adding it to the WSDL. Luckily the Zend Framework has allowed us to speed things up a bit by auto-generating the WSDL based on a class that is passed.

$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setClass('YourClassName','', null,$_SERVER['PHP_SELF']);

Now if you go to where you have this file located, let’s say:


You can then take a look at it!

Now, normally you will want to wrap this together with the server itself. To do so you would need to add a few more lines of code.
› Continue reading

Tuesday, December 29th, 2009 API Services, Zend Framework No Comments

Mac Tip: Hide/Show hidden files

I always find myself needing this snippet, so the way pages can disappear sometimes that have the snippet you need I always like to have my snippets on my own blog that I use frequently, and hope someone else may find them useful at some time as well.

So to show or hide your hidden files on Mac OSX:

defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

or if you want them to be hidden again, just change the TRUE to FALSE.

Sunday, December 6th, 2009 Uncategorized No Comments

MYSQL Shorthand If/Else Statement

I seem to forget this frequently and it is quite useful, so what better place to put it than here?

The IF() function in mysql is similiar to the PHP shorthand if statement:

PHP: ($var) ? ‘Var is true’ : ‘Var is false’;
MySQL: IF(COLUMN > 1,true,false)

SELECT count(U.id) as Active,
SUM(IF(US2.id IS NOT NULL,1,0) ) as Canceled
WHERE DateAdded BETWEEN '2009-09-01' AND '2009-09-02' 

MySQL IF() Function Documentation

Wednesday, December 2nd, 2009 MySQL 1 Comment
[ad code=1 align=center]