Browsing posts in: php

Laravel 4 – composer and packagist

Just released: the new Laravel version 4. The most important change is that laravel now embraces composer, the php package installer. This is good news if you want to use one of the many packagist packages available through composer, but this makes life a bit more complicatied as well. The old bundle system was a bit restricted but had one large advantage: ease of use.

What you need to keep in mind is that not all packages are structured in the way that laravel understands. For instance, you can install the original twitter bootstrap package but that leaves you with a directory structure like

But for laravel you need all img/js/css in a public directory like:

So how do we cope with this? Of course you can use the special laravel bootstrapper package, but that comes with pre-compiled bootstrap.
What we want is to configure bootstrap and then use Basset (the laravel asset compiler) to lesscompile/minimize all bootstrap resources and put the result in our laravel /public dir. But we don’t want to change anything to the bootstrap package because we want to be able to update to newer versions in the future.

Please leave a comment if you’ve found a beautiful solution to this.



Generating microsoft office documents (word, excel) on your webserver using php

Actually, this is much easier than you might think. The trick is to use the capability of excel and word to read html files

So just generate normal html, but use a content-type header line to force the browser to see this as a word or excel file: (using php)

header (“Content-type: application/msword”); or
header (“Content-type: application/”);
for word and
header (“Content-type: application/msexcel”); or
header (“Content-type: application/”);

I have never seen any difference between msword and, so if anybody knows the difference, please respond.

Then you might want to define the local filename. This can be done using the content-disposition header:

header(“Content-Disposition: filename=\”invoice_$invoicenr.xls\””);

For excel, just start generating a html table. The full table is used as excel sheet with its rows and columns.
For word, just start generating html code. It is interpreted by word. Make sure to use a FULL url path if you want to include images.

Here is an example to generate a word document:

Click here to test it.

Simple Tabs for your webpage with php

I’ve just finished a new version of the icelandic-horses website. Because it’s a fairly large site, I decided to use tabs on top of the page, to make navigation simple and intuitive.

Just looking for what is available on the net, i found lots an lots of nice implementations, however, they all were very complex, used a lot of javascript or everything was done with images/tables. I wanted a PHP/CSS solution without images, and in fact, it turned out very simple, and looks like this:

(no javascript and only 1 image used: a transparant dot (a gif file of 1×1 pixel, transparant)

Here is the class code:

And here is the CSS. Acutally the whole “tab” look is done with borders in CSS:

And here is a sample how to use this class:

You could use separate php files for each tab-page, or use one “big” php file with all pages. With additem, you just supply the url of the page itself.
If you use separate php files, be sure to include the code above in every file (with an include)
The $curmenu var indicates which tab to highlight. Be sure to set it right, otherwise all tabls are grey