MainelyDesign.com Blog

Php Tagged Blog Posts

The Funniest Error Message Ever - Thank You Eclipse

Posted on 10/18/2010 at 06:34 pm | Viewed 2,643 times | 0 comments

In a depature from my [normally] on-topic (i.e. dry) posts I had to post this error message up here. It made me laugh! I was working on the fattest CakePHP controller known to man (over 4,000 lines, I know... not skinny) when Eclipse ran into issues.  Eclipse gave a very descriptive error message, stating that it couldn't, well see for yourself:

CURL on Windows Doesn't Work in PHP 5.2.14 ISAPI

Posted on 09/07/2010 at 08:17 pm | Viewed 2,133 times | 0 comments

Just a quick post to let everyone know what I just found out- the version of CURL (php_curl.dll) that ships with PHP 5.2.14 for Windows ISAPI doesn't work!  That's right- it doesn't work.  I tried the MSI PHP installer package, manual installs, moving dll files into Windows and System32 directories all to no avail.  The culprit: a bad version of php_curl.dll (at least that's my best guess).  The other culprit: using ISAPI, but I don't have time to figure out FastCGI at this point.

Best Approach to Dynamic Javascript in CakePHP Views

Posted on 05/29/2010 at 12:36 pm | Viewed 3,759 times | 5 comments

I always knew in the back of my mind that there was a better way of creating dynamic javascript than the method I was using.  CakePHP has a great function as part of the $View controller:  $View->addScript($jscript, false) will add a script block to your template header.  This is the command I use to send javascript created in a Cake view up to the header, which is where most javascript should live.  The best approach to adding dynamic javascript to your CakePHP views is to implement PHP's output buffering, combined with $View->addScript().

Speeding Up Cakephp's ACL Component

Posted on 05/28/2010 at 12:12 pm | Viewed 2,991 times | 2 comments

I came across a posting today that changed the performance of my application tremendously and reinforced a concept I had forgotten about- mysql indices. I didn't realize my app was running slow until I implemented the mysql indexes below- no formal benchmark testing, but I would say speed improved by about 300%.  The improvement was most noticeble when you are building your ACL using the CakePHP suggested method.

Best Free Mysql Zip code Database

Posted on 04/20/2010 at 04:42 pm | Viewed 2,614 times | 0 comments

I'm sure every developer reaches a point when they will need to use a mysql database of zip codes in the United States.  Say you want to make a store locator and show how many miles a customer is from your store, or if you have some custom php logic that uses zip codes, you will inevitably need a mysql database of zipcodes. 

Controlling CakePHP Error Handling When Debug = 0

Posted on 04/19/2010 at 04:27 pm | Viewed 8,525 times | 3 comments

I finally had a client request a piece of functionality that required me to program CakePHP so I could better control the default error handling when the site is in production mode (i.e. debug is set to 0).  By default, CakePHP will throw a 404 page not found header whenever ANY errors occur on a production site with debug equal to zero.  This works great, most of the time.  But what about when you are having database connectivity issues?  Say when there are too many mysql connections to that overloaded shared hosting box?  Modifed CakePHP error handling to the rescue.

Setting Envelope-From in CakePHP's Email Component

Posted on 03/22/2010 at 05:56 pm | Viewed 2,874 times | 1 comment

I've setup a form that allows customers to sign up for an email newsletter and receive a coupon. I wanted to be able to track the bounced messages in case a legitimate customer's coupon was bounced for whatever reason. As I've learned, setting up the "return-path" for an email message isn't as simple as setting $this->Email->return = 'email@domain.com';  You have to use an as yet undocumented feature... $this->Email->additionalParams;

2 Neat Little PHP Tricks

Posted on 03/16/2010 at 04:15 pm | Viewed 1,993 times | 0 comments

In writing a function to validate bank routing numbers, I came across two simple techniques, that I know I will need to use again:

PHP Trick 1: Remove All Characters Except Numbers from a String

A simple little regex does the trick:

$routingNumber = preg_replace('[\D]', '', $routingNumber);

PHP Function to Validate Bank Routing Numbers

Posted on 03/16/2010 at 04:10 pm | Viewed 2,956 times | 0 comments

I needed to validate that a Bank Routing Number was valid, much like the algorithms out there to check if a Credit Card number is valid.  I did a little searching and didn't find a PHP function that would do the trick.  I decided to write my own, based on this javascript function, and publish it for anyone who wants to use it:

PHP Break Out of All Foreach or While Loops

Posted on 02/25/2010 at 02:44 pm | Viewed 3,272 times | 0 comments

Let's have some fun with PHP's break command... I didn't think it was possible.  I just learned (I've been programming PHP for like 7 years) that you can instruct break how many levels of nesting to break out of!  I'm not surprised that break in PHP allows you to specify the number of loops (or switch statements) to break out of, but I am surprised it took me this long to use it!

CakePHP Translate Behavior - Lessons Learned

Posted on 12/15/2009 at 08:29 am | Viewed 12,552 times | 6 comments

I've been working on setting up a multi-lingual web site for one of my clients.  I was excited at the opportunity to finally use CakePHP's built-in internationalization and locale functions.  However, I ran into some issues that I'm sure other newbies to internationaliztion will run into as well.  Here's some take-backs of what I learned while using the Translate Behavior in Cake...

Invalid Date Value Error in MySQL

Posted on 09/09/2009 at 02:26 pm | Viewed 1,669 times | 0 comments

I ran into an interesting issue with valid dates and MySQL on Windows.  I wrote a CakePHP import function that basically moves MySQL data from one DB to the other.  I never thought that I would see an error related to an invalid date, but I did.

What determines if a date value is invalid (read: warning) or unacceptable (read: error)?

Cakephp's Flay Class is Amazing - Examples Included

Posted on 09/08/2009 at 09:31 pm | Viewed 2,503 times | 1 comment

If you haven't checked out CakePHP's Flay class, check it out. It's one of the best utility classes for text output in CakePHP.

I just noticed that my blog was using the same META description for all of my blog entries- not good for SEO.  Instead, I want to pull a fragment of the article copy and use that as my META description.  I currently use this convoluted way to get my summaries from the article copy, so I decided to try using the Flay class.  I've used it before but I'm glad I revisited it... it's amazing!

Using Exif in PHP on Windows

Posted on 08/28/2009 at 09:40 am | Viewed 1,328 times | 0 comments

I'm trying to use the exif functions in PHP on my Windows XP computer.  I want to read the meta data that is recorded by my digital camera (exif - exchangeable image file format).  I like the idea of storing that exif data in the database, so it's searchable. I wasn't having any luck with exif_read_data(), but finally found this posting.

Changing Filetypes Shown in SWF Upload File Browser

Posted on 08/25/2009 at 04:17 pm | Viewed 2,034 times | 0 comments

It's easy to change which file types are allowed to show up (and are displayed) when you browse for files to upload through SWF Upload.  SWF Upload makes it easy to upload multiple files in PHP.

I just had to hunt through some source files until I found this in my SWF Upload config. (goes in the new SWFUpload() function)

Displaying phpinfo() without CSS styles

Posted on 06/09/2009 at 10:18 am | Viewed 3,365 times | 1 comment

I wanted logged in users to be able to see the output from phpinfo(); within Site Avenger.  The problem with using phpinfo() is that it outputs a full HTML page, CSS styles and all.  In the past this has been fine, but now I wanted to show the phpinfo() within the Site Avenger layout and CSS styles.  I came across a simple, yet highly effective solution...

Full Tag List

Meet Site Avenger - Hosted Content Management System

Powered By: Site Avenger | Site Production: Saco Design