Chrome browser masking PHP errors

I thought I was going mad for a while, but it turns out that sometimes spotting php error messages which come back from the server to the Google Chrome browser can be really tough.

If the error is inside an html element or attribute of an html element you’re going to struggle to see it in Google Chrome…

<a href="<?= $Model->fakeFunction(); ?>">link</a>

If $Model doesn’t have a method called fakeFunction then php will spit a “Fatal error: Call to a member function” error. The page that is displayed in Chrome won’t show you the error and viewing the source will also hide it from you.

Even the elements tab in Chrome Developer Tools won’t show it.

There only way I’ve been able to find the error content is to look at the network tab in Chrome and view the raw response of the document back from the server.

A few hours lost on this one!

Add global Twitter Bootstrap modal listeners

If you’re ever browsed the Twitter Bootstrap javascript documentation then you’ll know that the modal parts of the Bootstrap library require some javascript to show and hide them.

Part of the javascript is related to events which you can attach listeners to so you know when your modal shown and hidden.

What they don’t tell you is that you can add a single global (or semi global if you want) listener to all modal events which will fire when any modal is shown or hidden.

$('body').on('shown', '.modal', function () {
 
	console.log('we have shown a modal');
 
});

For example the above will console log “we have shown a modal” when any modal is shown. You can switch the shown event to be show, shown, hide or hidden.

Cloning a github project

When you first start on a new web project amongst a group of people someone is likely to create a github project. Rather than then all individually creating a new project on your machine you can do the following…

1) Browse to your sites folder in Terminal. We’ll create a new folder for this new project in the next step.

2) use the command git clone git@github.com:whatever folder-name to not only clone the existing github repo, but also to create the folder you want it in

3) cd folder-name to navigate to that folder

4) git add remote remote-name git@github.com:whatever to add a new remote

And you’re done.

As an added option, if you have already created the folder you would like then you can replace 2) above with navigating to that folder, then…

git clone git@github.com:whatever . note the . character to define ‘current folder’

Fix apache after upgrading to Mountain Lion

Every time I upgrade OS X something breaks with apache or php or both.

The steps for me to fix it this time was…

* Open your httpd.conf file
* uncomment the Load php5 module
* uncomment the load vhosts module

in etc/apache2/users

* duplicate Guest.conf to harrybailey.conf – replace harrybailey with your username obviously
* edit harrybailey.conf to read:

<Directory "/Users/harrybailey/Sites/">
    Options Indexes MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Note: as Michal mentions below you may want to add +FollowSymLinks to your options too. This allows the system to follow any symbolic links you have set up.

AGAIN – replace harrybailey with your username.

* save the file

You may also get a php error which includes…

“It is not safe to rely on the system’s timezone settings”

The fix for that is
* navigate to /etc/ and rename php.ini.default to php.ini
* edit your new php.ini file – find “;date.timezone = ” (no brackets)
* update it to read “date.timezone = Europe/London” (no brackets) – if you aren’t on GMT then find your relevant timezone string and use that
* save the file

* open terminal
* submit the line:
sudo apachectl restart

That did it for me. Hopefully it will do it for you too.

I was first seeing the default html file in the /Library/Webserver/Documents folder
I was then seeing 403 errors for all vhosts that I has setup
Personally I saw these problems after upgrading from Lion (10.7) to Mountain Lion (10.8)

Export structure and data from Navicat Premium as SQL

I was trying to find the quickest way to export both structure and data from all tables of a database from Navicat Premium and came up with these steps:

* Use the backup tool to create a backup of your database
* Right click the backup and select to Extract SQL…
* Save to wherever you like

You can now use that .sql file to create a new database wherever you like.