Servage Magazine

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

Archive for August, 2015

Basic DOM operations without jQuery

Saturday, August 29th, 2015 by Servage
javascript-badgeToday most websites rely on Javascript, and many of them on jQuery or similar Javascript frameworks that enhance the capabilities of Javascript by making more functionality and effects possible. Entire web apps are written in Javascript, and they are getting very close to real desktop applications. You can utilize jQuery, Prototype, Ember, Angular and many others for rapid development, however, sometimes you want or need to go back to basics, and rely on pure Javascript without all the fuzz from the other frameworks. Sometimes you just need good old Javascript and nothing else. Therefore it is nice to know, that even with regular Javascript you can actually also do lots of ...

Working with logging and errors in Laravel

Sunday, August 23rd, 2015 by Servage
oops-errorLogging and error-handling is built right into Laravel 5, so you do not need to build own exception handlers and logging mechanisms as with own custom projects. This is one of the many benefits of using a ready-to-go framework like Laravel 5. Configuring Laravel logging You can set various levels of logging, and choose which grouping you want in your log files. You can change the logging related values in the "config/app.php" file. The "debug" paramenter is set to the environment value APP_DEBUG by default, so you can set it to a general value in the config file, or change locally in the environment file. Note that debugging should always ...

Handling errors nicely in PHP

Tuesday, August 18th, 2015 by Servage
php-buttonWorking with PHP requires you to consider how to handle errors. The errors can be various kinds and have different consequences for the code execution, and have to be handled accordingly. Errors are generally speaking scenarios where the code encounters a problem because of a given scenario that does not meet the criteria and expectations given by the code. There is no way you can expect to develop a script that never encounters errors, and therefore you should put proper care into your error handling process. If not, then users may experience odd and unexpected behaviour which frustrates and leads to lower satisfaction. More severely it may even lead to broken data ...

Useful Laravel array utility functions

Friday, August 14th, 2015 by Servage
laravelLaravel includes many useful functions. This article contains a list of great utilities for handling arrays. The function "array_add" inserts a key with a corresponding value to a given array if the key is not already present in the array. $values = ['name' => 'John']; $array = array_add( $values, 'age', 35 ); // Value of $array: // ['name' => 'John', 'age' => 35] The function "array_divide" returns two arrays with the keys and values of the original array respectively. list($keys, $values) = array_divide(['name' => 'John']); // Output values: // $keys: ['name'] // $values: ['John'] The function "array_dot" turns a multi-dimensional array into a flattened one-dimensional array using dot-notation to indicate the old depth: $array = array_dot(['foo' => ['bar' => 'baz']]); // Value of array: // ...

Building an interactive web app from scratch

Monday, August 10th, 2015 by Servage
javascript-codeStarting a web project or modernizing an existing one often confronts you with decisions about how to structure the code, and which web technology to use. Nowadays many projects consist of a backend framework powered by PHP and MySQL, plus a frontend framework consisting of Javascript powered HTML and CSS generation. You can rely on existing frameworks for this purpose, but sometimes it makes sense to build something on your own. This is especially useful if your project has special requirements unfulfilled by the other frameworks, or if your project is very small and concrete, so using a framework would impose to much overhead. Building a small web app Below you will find ...

Handling model data in Laravel collections

Wednesday, August 5th, 2015 by Servage
collectionThere is a fluent collection wrapper provided in Laravel which makes handling many models very efficient. A collection is basically a list of models, like an array, which can be processed using various methods. The collection itself is an object which provides a range of utilities, however, it also implements array access, so you can perform array operations on it. This makes it especially powerful. It is very easy to get a collection, because you get it by default from the Eloquent model database query methods. For example if you retrieve all users using the standard methods for such a database selection, you will get a collection of user model instances. Creating a collection from ...