/var/log

Tag: PHP

One Laravel codebase with multiple databases and hostnames

What we want to achieve: These are the steps needed to accomplish this. Symlink to codebase Each hostname should have be a symlink to the original codebase. For example our codebase is in /var/www/codebase and if we have a new hostname we should create a symlink to this codebase, for example a symlink /var/www/host1 pointing […]

WordPress Users, Roles and Capabilities

I find the capabilities one of the most difficult to grasp concepts in WordPress development. On one hand, you have the capabilities of a custom post type and on the other hand you have the capabilities of a user or user role. And then you have the 2 other capabilities options you can set when registering a custom […]

Show custom post types in category archives

Custom post types are not displayed in the category and tag archives by default, even if you indicated in the register_post_type call that it should support these taxonomies. The way to include them in the category and tag archives is to use the pre_get_posts action: add_action('pre_get_posts', 'mycode_pre_get_posts'); function mycode_pre_get_posts($query) { if ((is_home() || is_category() || […]

Single selected taxonomy in WordPress

The category taxonomy is by default a multiselect widget that uses checkboxes. There are some ways to only allow one selection, like implementing your own Walker_Category_Checklist. But the most simple solution is just replace the checkbox inputs with radio input boxes with some Javascript. In the example below, I have a taxonomy "level" that I want […]

Laravel dynamically detect environment

Laravel 5.2 comes with a .env file and tells you to not check it in. The idea behind it, is that you will have another .env file on your development, testing and production server. But if you want to dynamically detect and set your environment, this does not work too well. To make dynamically detection and […]

Laravel change paths

Change storage path To change the storage path in Laravel (tested with version 5.2 and 5.3) you have to extend the Application class and then override the storagePath() method. You can do this all in the bootstrap/app.php file: class MyApplication extends \Illuminate\Foundation\Application {   public function storagePath() {     return $this->basePath . '/../storage';   } […]

Sami - a PHP API documentation generator

I recently was looking for a way to create clear and nice looking API documentation from a library I made (BSF GitHub and API docs). I looked into phpDocumentor 2, apigen, doxygen and Sami and decided to go for this last one. It has a real nice looking default theme and is themeable with twig. But […]

UTC date in javascript, php, mysql and sqlite

It can be very challenging to work with dates and times across different timezones. In this post I explain some of the things I do to make this work. I focus on Javascript, PHP, MySQL and SQLite development. MySQL The most important action first - put the connection session in UTC mode: set time_zone = […]

Store mcrypt values from PHP in MySQL

The mcrypt functions return a binary string, so you can store it in a VARBINARY or BLOB field or as VARCHAR or TEXT if you first base64 encode it. When using the CBC (Cipher Block Chaining) mode, the input is divided into blocks of X bytes. The last block is then padded with NULL bytes […]