Categories
Uncategorized

Slim PHP Route Does Not Appear To Be Working, Always Chooses / Route

Most people probably run Slim PHP the way it was intended.

By adding a .htaccess file into your directory and letting it do it’s magic thing. However, I have complete access to our server, and choose not to allow .htaccess files. I instead put all of my apache mod_rewrite statements into my apache config files.

However, I just found out that if you are running your Rewrite’s through your <VirtualHost> tags, then one of your server variables may be incorrect. I am not sure if this is Apache’s fault, or PHP’s. However, a simple fix is just set it yourself.

At the top of your PHP file, put the following.

$_SERVER[‘SCRIPT_NAME’] = ‘/RELATIVE_PATH_TO_YOUR_SLIM_APP_FILE.php’;

most people would probably use the following.

$_SERVER[‘SCRIPT_NAME’] = ‘/index.php’;

Categories
post

Pre-Commit Fails When Removing a File From Git

I just blogged about automatically running PHP Lint when committing a file into the repo. Well I also had the joy of it failing because I removed a file.

If you get “Could not open input file: abc.php”, then you may have the same problem I did.

There’s an easy solution. The pre-commit file looks for all changed files. Technically, a removed file is changed, but it also doesn’t exist when you go to run php -l against it.

Open your pre-commit file, and change the line that looks like this:

exec(“git diff-index –cached –name-only {$against}”, $output);

to

exec(“git diff-index –diff-filter=ACMRTUXB –cached –name-only {$against}”, $output);

Categories
post

Run PHP Lint before committing to GIT

This is going to sound stupid, but if you don’t have rock solid unit tests in place, one of the things you should be doing is running PHP Lint.

What is PHP Lint?
Simply stated, it checks your php file for syntax errors. How many times have you forgotten a semi-colon, or had unmatched curly braces?

How do I run PHP Lint?
It is very easy to run from the command line
php -l your_php_file.php

Using GIT? You should setup a pre-commit hook to always do this so you don’t push something bad into the repo. I am guilty of doing this in the past. 🙁

Here is a great post by Travis Swicegood about setting this up.
http://phpadvent.org/2008/dont-commit-that-error-by-travis-swicegood

One thing to remember is that you also have to make the script executable.
chmod 744 .git/hooks/pre-commit

Categories
post

phpUnderControl javascript fix for Internet Explorer

There are two errors in the phpUnderControl javascript that causes IE to work like the other browsers.

Basically, you may not be aware that the “home screen” auto updates in other browsers. I kept refreshing like a madman until I opened it in another browser and saw it happen automatically. Then I dug in and fixed it.

Here is the patch:
[code]
@@ -16,7 +16,7 @@
if(d != null) {
el.setStyle( {
‘height’: d.getAttribute(‘height’) + ‘px’,
– ‘width’: d.getAttribute(‘width’) + ‘px’,
+ ‘width’: d.getAttribute(‘width’) + ‘px’
} );
}
delete d;
@@ -26,7 +26,7 @@
var d = el.contentWindow.document.body.scrollHeight;
if(d != null && d > 20) {
el.setStyle( {
– ‘height’: (d + 50) + ‘px’,
+ ‘height’: (d + 50) + ‘px’
} );
}
else {
[/code]