Create Autoloader using Composer

  • Create a new file composer.json in the main folder and insert the just curly brackets

  • Run, to generate the autoload structure :

Acme is a example of Company/Project name, and src is the directory that contains all the files we want include in our project.

  • Run, to generate the psr-4 autoload file, the command:

The content of the file will be the following one:

  • Require the file autoload.php in your main project file (e.g.: index.php):

  1. Use namespaces Acme in your project for the file not in subfolder but just in src: So for example if you have the class Test.php in src you just need to use this.

You don’t need to use src in your namespace because the autoload has the $basedir on src.

The general rule is >>> what is inside the namespace + Class Name

So for example if you have the folder User in src for the class Person:

You must have the following code structure:

Class Person.php in src/User/:

index.php:

Read a JSON file with php

Get the JSON content using file_get_contents() and to not avoid warnings specify the sources:

To read the file with an http request specify http/https:

To read the file form the filesystem:

decode the JSON using json_decode():

Use var_dump or print_r to understand the data structure. If for example the data content is:

To print the database name of databaseOne:

To loop through the array:

To print the database name for each entries:

Composer basics

Start new php project:

Install a new packages with:

Use https://packagist.org/ to find the exact component name

In order to get the latest versions:

Uninstall packages from composer:

Search package from composer:

Shows a list of installed packages that have updates available:

You should always run the validate command before you commit your composer.json file:

Install WordPress updates without ftp

If you have wordpress in a local machine and you want update the wordpress version without enable ftp you can add to the wordpress config file wp-config.php this setting:

remember you need to have permission to write in the wordpress folder. If you have a LAMP server make sure you have the user set to www-data.

sass installation on Mac – Gem::FilePermissionError

If you receive the following error during sass installation:

try to use this command:

Docker ubuntu 16.0.4 on QNAP Container

Create and setup the container

Change the root password:

to know the ip address we need to launch the command ifconfig but is not installed by default.

Install networks tool:

To allow connection from terminal enable ssh launch the command:

Install also:

sudo service ssh restart

Docker: docker-container

Launch the commands from the container folder

  • Install the machine docker-compose build
  • Start the services docker-compose up -d
  • Stop the services docker-compose stop
  • Stop and remove containers, networks, images, and volumes docker-compose down
  • See active containers docker ps

doing this you can understand the port to see the webserver.

Clone this repo if you need a LAMP webserver

Media Query

Media Query

Mobile

Mobile portrait

Mobile landscape

Tablet

Tablet in portrait and landscape (iPad)

Note: use just min-width if you want use for responsive.

Tablet in landscape (iPad)

Tablet in portrait (iPad)

Mobile first approach

You should use min-width and then raise the pixels for different viewport:

NO Mobile First

Target IE with media query

Fontawesome icons inside a palaceholder

This is one way to use fontawesome icons inside a palaceholder:

in the CSS you have to use this code for the class fontAwesome:

After that in the HTML you have to add the **fontawesome class** first and then the **fontawesome icon code** inside the placeholder:

and it’s done!!!

You can simply apply the class every time inside your input with the relative code in the placeholder.

And even more, you can use this method by entering the code into a generic element such as a link or a simple text using the same class “fontAwesome” used for the placeholder:

You can see the result or read the post from my codePen post.

See the Pen FontAwesome and placeholders by Massimiliano Ranauro (@huckbit) on CodePen.