Dependency Injection

Dependency Injection

Dependency injection is a design pattern which allows you to inject your dependencies into a class, rather than have them loaded from within that class. This blog post on PHP dependency injection will be an example based post without too much commentary from me.   Typically when we write our classes they require functionality from other classes. One way of achieving this is to include and load a new instance of the dependency within our class. Another possibility is that…

Read More Read More

Zend Opcache improves page load speed

Zend Opcache improves page load speed

Zend Opcache in PHP improves your page speed by compiling code into machine code and storing the byte code in RAM. With each subsequent hit to a resource code is served from memory rather than being compiled again. PHP is an interpreted language. What this means is the unlike languages like C / C++, PHP is not compiled once to machine code and then executed from the binary each time. With PHP, each time a page is viewed on your…

Read More Read More

PHP Queues with php-resque

PHP Queues with php-resque

If you’ve been doing PHP development for more than a week you’ll have heard about the benefits of message queues. If you’re totally new to this world and have not heard of queues you should google for more info. At its most basic though a message queue allows your application to offload long running tasks to be completed as background tasks, thus speeding up the front end for your visitors. For instance, on CuteBaby.co.za when a user registers their little…

Read More Read More

WordPress errors uploading images

WordPress errors uploading images

During work on Cutify Media Marketing’s new WordPress competition sitesĀ I encountered a problem with WordPress image uploads. The following code was called to attach an uploaded image to a WordPress post and set it as the WordPress featured image, or post thumbnail as its called in the code.. The problem is that the code kept failing. We checked the logging of is_wp_error and found the following error: Our site uses SSL (https://), however on the server itself we use a…

Read More Read More

Laravel belongsToMany relationship

Laravel belongsToMany relationship

There are often times when your data has a “belongsToMany” relationship. Laravel handles this relationship really beautifully! I learn best by example, so we’ll do this post as an example I’m currently working on. In our application we have multiple related websites. Each of these sites stands on its own with users being able to register individually on each site. We wanted to update this so that when a user registers on one site their details are automatically pushed to…

Read More Read More

Show only user’s own media files in WordPress

Show only user’s own media files in WordPress

The problem I recently did a site for a client in wordpress which required a custom user type. These users needed to be able to use the media library but only to see their own media files. One would have thought that this is actually quite a common scenario so I thought that implementing it would be simple enough… In my research I came across a wordpress plugin called “View own posts media only”. This apparently worked well for a…

Read More Read More

Creating a new laravel site

Creating a new laravel site

Having installed Laravel you’ll now want to create your first Laravel website. Creating the new Laravel site In the command line navigate to the parent directory which contains all your web projects. On my Ubuntu system my projects are all in /var/www/html, so on the command line: cd /var/www/html Decide on a name for your project. We’ll call ours my-cool-website. Now run the new command from the command line like this: laravel new my-cool-website            …

Read More Read More

Node / NPM to manage JS / CSS in Laravel

Node / NPM to manage JS / CSS in Laravel

To manage your js and css files in Laravel you could place your js and css files in the public directory, but using the /resources/assets folder you can add your js and css (sass or less, etc) in there. You then need to compile these with nodejs and NPM. To install nodejs / npm on Ubuntu you can use sudo apt-get install nodejs Once installed in a terminal window navigate to your Laravel project directory and type: node install Once…

Read More Read More

Installing Laravel

Installing Laravel

Laravel is a PHP framework so we need to start with a L(W)AMP server of some sort. We recommend PHP 7 but from PHP 5.6 will do. Laravel is easiest to install with Composer. Once Composer is installed according to their instructions, we can use it to install Laravel. There are different methods of installing Laravel but I prefer installing it as a global package on the system. To do this, on the command line type: composer global require “laravel/installer”…

Read More Read More

WordPress wp_remote_get

WordPress wp_remote_get

I was recently working on a project which involved using WordPress cron for some automated tasks. Although the function wrapping the call to the WordPress even scheduler reported being called, the ‘work’ was not being done (in this case retrieving data from a remote server). This was particularly strange because if I ran the functionality manually it worked. Note: I inherited this system from another developer so any references to code duplication are not of my doing! Upon closer investigation…

Read More Read More