Servage Magazine

Information about YOUR hosting company – where we give you a clear picture of what we think and do!

Archive for March, 2013

How to use PHP namespaces

Thursday, March 28th, 2013 by Servage
PHP namespaces are a convenient way to organize your code. Imagine a project where you have a lot of classes, somewhat organized by class names. You will often see that developers try to name the classes according to the part of the code they belong to. Otherwise the shere amount of classes can quickly make it impossible to understand which part the code belongs to, or you run into naming conflicts, because common class names may already be used somewhere else. This is where good naming conventions comes in handy, so structure your classes well. However, even more convenient are PHP Namespaces. They can structure your classes in a folder-like ...

Choose proper font typography

Monday, March 25th, 2013 by Servage
When it comes to designing websites, many designers use their own unique style, and chose among the fonts they discover and find useful for a particular purpose. However, many designers are not typographers - you can't be an expert on everything ;-) This often font-selection to fit a particular need becomes a randome selection between things the individual designer finds interested. Also, using multiple fonts in a website is not uncommon, especially since you often need various sizes, or even different fonts, to properly distinguish different types of headings and text in your layout. The font selection process becomes a lot easier with the following font-stacks. They have been grouped by typographical ...

Use command-line PHP arguments

Thursday, March 21st, 2013 by Servage
When developing on a local machine, sometimes it makes sense to create scripts used as tools run via the command line. This can even be useful if you're a PHP developer, and like to develop PHP scripts for other purposes than web-development. Since PHP has access to your files system, you can easily program PHP scripts to do something on your system, manually of by cron-job, especially if you're on a Unix computer. It's important to notice that some environment-specific things change, when working with the command line, rather than a web server. E.g. there are no GET or POST parameters etc., but instead you can work with arguments passed to ...

CSS form highlight

Tuesday, March 19th, 2013 by Servage
Do you know the standard web form blue highlight when you're filling out a form? It's pretty nice that you can see which field is active, where you're currently editing, and browsers have simply introduced a standard blue glow or highlight around the particular form element to illustrate this. It looks good an fulfils it purpose, but did you know that you can actually customize this? Pretty much anything rendered by the browser can be customized with CSS, and this form highlight is just one of them. Make use of that, and make your forms look like an integrated part of your website's style. It just looks better :-) Form HTML <form ...

Relationship types between models

Saturday, March 16th, 2013 by Servage
When you work with data models you will come along the question of relationships between your models, or data tables. Most frameworks support this out of the box, and come with advanced features for handling such issues. You can take a look at the documentation for relationships for some of the major PHP projects on the matter: Yii Framework CakePHP Propel What do the different types of relationships mean? There are four basic types of relationships between models, and they are all distinguished by the way they store the foreign keys, i.e. how the relation is stored in the database. Example 1: Author has many Books You have an Author table with a field Author.id. You have ...

Class inheritance explained

Thursday, March 14th, 2013 by Servage
When your work with object oriented programming you will often get across inheritance, which is the concept of classes providing functionality to each other, by either passing it on to a child class, or inheriting it from a parent class. In modern days this has been extended with other concept like PHP does with "implements" and "traits". Understanding class inheritance is significant for your development workflows and opens up so many doors to more advanced and versatile coding, which is a great benefit for your project. Integrating similar code, inheriting same code, working object-oriented is the key to efficient work. Types of inheritance Single Inheritance Multilevel Inheritance Multiple Inheritance Hierarchical Inheritance Hybrid Inheritance Each of these types of inheritance has ...

Web-based code editor for your website

Monday, March 11th, 2013 by Servage
Are you coding on a local server and upload to your hosting account? Or do your maybe even code straight on the web server in the live page? Either way, you may strongly consider a web-based coding editor, which integrates your development environment with your hosting account even better. Below is a list of some great tools to help you. CodeAnywhere https://codeanywhere.net/ Very robust development tool with Code editor, FTP Client, CSS Editor, Dropbox support, Sandbox, iPhone App, iPad App, Android App and BB Playbook. Coderun http://coderun.com/ Mature tool with projects in multiple languages, syntax coloring and code-completion, compile code and review build errors, run and debug code in multiple platforms, and more. Koding https://koding.com/ Brand new, formerly ...

Applying shadow-effects with CSS

Saturday, March 9th, 2013 by Servage
Have you ever designed a website which used shadow effects for certain elements? For example a menu-box or a picture-frame, which should look like it has a shadow? This type of effect is very common on websites, and has previously often been achieved with using underlying graphics, like border or shadow images, which are included as bacground pictures, or maybe added around the desired item with a table structure. The new CSS versions allow the browser to understand and render shadows itself. This relieves you of a lot of extra hassle, going through a graphics editor, and makes it more simple to use such effects. CSS becomes more powerful every day, ...

Using maps on your site

Wednesday, March 6th, 2013 by Servage
There are plenty of map providers out there, and choosing one can seem difficult. Google Maps, Bing Maps, OpenStreetMaps, what to choose? Honestly I don't know. However, the good news is that most providers give a great performance and good libraries to integrate your preferred mapping solution into your website quickly. Leaflet is "An Open-Source JavaScript Library for Mobile-Friendly Interactive Maps" and another example of how this is done quickly and nicely, with a good looking result and beautiful code. Integration example // create a map in the "map" div, set the view to a given place and zoom var map = L.map('map').setView([51.505, -0.09], 13); // add an OpenStreetMap tile layer L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { ...

Create a sticky footer with CSS

Tuesday, March 5th, 2013 by Servage
It often looks good to make the footer of your website "sticky" to the bottom of your page. This can be achieved with CSS, and is actually rather simple, knowing the right code to do it ;-) The following snippet was found here. Try it out. Sticky footer CSS #footer { position:fixed; left:0px; bottom:0px; height:30px; width:100%; background:#999; } IE6 hack for compatibility * html #footer { position:absolute; top:expression((0-(footer.offsetHeight)+(document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight)+(ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop))+'px'); }