Web developer skills, tools, frameworks, do I really need to know all this stuff?

When I first started in web development I started by learning PHP along with HTML, CSS and Javascript to create the UI of web software system I was building.

After a couple of years I decided to start using a web framework to make my development of web based software less time consuming.

It was around this time period that I was of the opinion that I needed to study whatever skills I was learning to point of mastery.

Of course although most skills where learned in depth learning any skill to point of mastery is ongoing.

Below is a diagram showing my opinion on learning new skills …

It is my belief that the bulk of the learning is done at the very beginning with only minor gains being made after that.

The minor gains would be the ins and out of the skill and the areas of the skill that will not be used on a day to day basis.

Some of the minor areas would include areas of the framework that do not work as expected and you have to spend a little time figuring out how to do it using the framework itself.

Most of the areas of the skill that are going to be used daily are within the “front peak” area of the diagram.

The diagram is ongoing and the right area of the chart is always expanding, this represents the ongoing updates to the skills you would need to learn to say you are “up to date” with the skills.

Although this area would most likely not include the “front peak” again it is still ongoing never-the-less.

So going back to what I was saying I use to believe that I had to take my learning all the way to the end of the chart and going further that I had to have some commercial viable projects that I have built using the said skill.

Only after doing the above could I say that I had the “skill”.

Looking on the job boards today I can see that lots of employers are asking for enormous amounts of different skills.

Why would a company need all of the these skills they are listing from both 1 employee and every employee within the company?

I am not going to harken back to the “good old days” but I am reasonably sure that these skills use to be more spreadout over different employees.

The skills being listed are skills needed in multiple roles meaning each and every employee is wearing many hats rather than 1 employee being this and 1 employee being that.

Some of the skills are totally unrelatable such as needing to know 4 programming languages (core skills) and various frameworks and tools related to each of those 4 languages. Or listing graphic design skills along with UI programming skills.

If you go to University you go there to learn “web development” or “graphic design”. So are these companies telling me I need a degree in “web development” and “graphic design”? How long would you need to learn at University to do that? Around 6 years, 3 years for each course and that is the tip of the iceberg.

This gives the impression that these companies cannot possibly be serious but in some cases you actually find that they are serious.

How can anyone learn this number of skills to the point of mastery or even in depth?

Not all of the skills listed on these job descriptions take an equal amount of time to learn. Some of the skills could take as little as a couple of hours whilst some can take as long as year.

To some of the companies there is no differentiation between these, either you have the skill or you have not got the skill.

I have seen job descriptions listing “plugins” as needed or desired skills. Plugins should not even be listed as skills, plugins are just modules that can be used by the core language or framework.

Most programmers do not even look at plugins as requiring any learning they just import the plugin and get stuck in. The degree of learning for a plugin is so minimal that it is hardly worth mentioning let alone listing as a required or desired skill.

Admittedly because some employers are asking for plugins as a skill I have started listing plugins I have used in my skill set. Last year I was not doing this though.

Here is my experience on how long certain skills should take to learn from scratch, when I say “learn” I mean to get over the big spike on the chart above, of course you can continue learning additional parts after the big spike and the learning can be on going but I am just talking about learning something enough to be useful enough to produce something …

Core skills – Java, PHP, C#, Javascript, SQL etc – 6 months
Frameworks – Laravel, Yii / Yii 2, Symphony – 1 month
Mini frameworks – Express, Lumen, NodeJS, React – 2 weeks
Plugins – anywhere from a couple of hours to a couple of days

As you can see it is only the “Core skills” that in my opinion take a long time to learn, after the “Core skills” the time to learn the other areas such as “Frameworks”, “Mini frameworks”, “Plugins” decreases dramatically.

Potential employees are being rejected on the grounds of them not having the certain skills listed above.

The potential said employee is going to be with the company for years and is being rejected on the grounds of not having a skill that would take 2 weeks to 1 month to come up to speed on?

It is not that the employee even has to take 2 weeks to 1 month to learn the skills on company time, the employee can still be productive whilst learning the skills. An employee can start on the company work and learn the skill as he / she goes along.

No big deal in my opinion.

Sometimes a company will claim they rejected you because they did not think you could “hit the ground running”.

If challenged on why the said companies thinks you will not be able to “hit the ground running” you will get a list of supposed “technical incompetencies”.

This list was most likely not produced at the time but the hiring manager went by his or her “gut feel”. Now that you have challenged it the hiring manager will produce a list of your “technical incompetencies”.

This can seem very daunting but what most people do not realise is that coming up with a list of someone elses “technical incompetencies” is the easiest thing in the world to do.

Everyone has some incompetencies that can be focused on, the problem is you do not get to see the hiring managers or any of the other employees incompetencies within the said company, so it gives the impression that only yourself is incompetent.

What you will also find is that the “technical incompetencies” are of a trivial nature or are not really incompetencies at all.

As an unrelated example, hiring manage preferred the red colour over the blue colour but never specified that in the requirements and will now not hire you because you did it in the blue colour.

Hiring preferred “this” way of coding over “that” coding but never specified that and will not hire you for that reason.

An example could be “Type Hinting”, a number of years ago it was not possible to use “Type Hinting” in PHP so in your “technical test” you may write a method as follows …

Rather than using “Type Hinting” like this …

Some of my personal PHP projects I work on do not use “Type Hinting”, a lot of PHP web software projects have no “Type Hinting” in them.

However this is exactly the sort of area the hiring manager would bring up as a “technical incompetence”.

In my projects where I have used “Type Hinting” it was no big deal to start using it. It did not take me any extra time to start using it and it was not difficult to start using it.

It was not a “technical incompetence” it was something I just did not do out of choice and personal preference.

Like I say to start using it was no big deal and certainly not something that warrants rejecting a potential job applicant on.

Job application test …

Coded a small web app without using Type Hinting – “We do not think you can hit the ground running”

Applicant …

Hears the answer and is disappointed he did not get the job. Decides to implement Type Hinting into the small web app he just made for the interview just to see how long it would take, took him 15 minutes to implement.

15 minutes to implement! This could have been done on his morning break, all it would have required is for someone to tell him to start using Type Hinting. Hardly a deal breaker given that the said applicant would have been at the company at number of years.

Next job potential job.

Employer business …

“Yes we need HTML, CSS, PHP, Laravel, NodeJS, Express”

Applicant …

“Fantastic I have all these skills.”

Employer business …

“Ohh actually we also need React” – “We do not think you can hit the ground running”

Applicant …

Decides to learn React on his own time to see how long it would take. Gets over the learning curve in 2 weeks. Again hardly a deal breaker given that the applicant would have been at the company a number of years.

Of course there will be people out there thinking “Well if you are that bothered, why do you not just learn React and then apply for the said jobs”.

This would be OK provided there was not different combinations of skills that need to be learned, one company wants one thing one company wants another thing.

One company wants Symphony one company wants Laravel, one company wants AngularJS one company wants React.

These types of skills are parallel to each other, if you learn one it is not worth learning the other because they are both designed to accomplish the same goal.

This means you basically have to learn parallel skills just to get a job in a specific type of company.

So lets start putting it to the businesses …

I am an applicant and I have the following skills …

HTML, CSS, JQuery, PHP, MySQL, Laravel.

Everything I need to build a perfect fully function web based software system.

Company does not want these skills but they want something similar to this …

HTML, CSS, MongoDB, NodeJS, Express, AngularJS, PHP

Basically this is about the stack of technologies, give or take, the first set of skills is the traditional LAMP stack of skills the latter is the MEAN stack of skills.

Applicant …

“So employer business what made you decide to use the MEAN stack of technologies over the more traditional LAMP stack of technologies?”

Employer business …

“We decided to use the MEAN stack of technologies because with the emergence of NodeJS we can now compile Javascript and this makes the software system more faster and efficient over the traditional LAMP stack of technologies”

The above is a typical text book answer, the above sentence could have been taken straight from the NodeJS website itself. The real reason is because the MEAN stack is the latest web development fad.

Lets carry on …

Applicant …

“So what types of web based software systems do you build?”

Employer business …

“We build a range of web software systems for our clients such as custom CRMs, Online Stores, Project management tools, Workflow tools”

In other words nothing that would be required to be “ultra” fast and efficient. Nothing that is really scientific and cutting edge. Nothing that would require the latest advancements in processing power. Nothing that could not be built using the traditional LAMP stack and be almost as fast and efficient.

When the term fast and efficient is being used remember it has a context, the gain made will most likely be in the form of milli-seconds.

This may be useful in some areas but for your general business tools such as what businesses need and what most web based software system companies are providing the extra 0.001 milli-second gain per page load is generally not going to matter.

But lets say that all these areas matter, the extra 0.001 milli-second gain per page load matter, lets carry on …

Applicant …

“So you mentioned you aim for speed and efficiency in the web based software systems you use. Why then did you not use Java over NodeJS as Java has been around longer, is tried / tested and is more faster and efficient than NodeJS?”

Most likely you will not get a real answer.

The point is there are tools and languages for the scientific world, there are tools and languages for the speed and efficiency world.

These tools and languages have been around for years and are better at their “niches” than NodeJS. So why was NodeJS chosen if “speed and efficiency” was the goal?

The companies that are really scientific and cutting edge do not expect their “scientists” to “hit the ground running”. It is recognised that the said subject will require research and development.

Breaking into something that is truely scientific and cutting edge is not something a “timescale” can be given to. If nobody has done it before how can anyone know the “timescale”?

Having said all of this I have started to learn new skills such as NodeJS and the rest. I am finding it super enjoyable and it is giving me the same feeling of enjoyment I had when I first started programming.

It is just a bit of a bother that employers are not willing to take a chance on a potential employee and train them up as they go along especially when the employee will be with the company for a large period of time.

So to answer the question of this post, yes it is important to learn as many of these skills as you possibly can even if you do not take all of the skills to the level of mastery.

Some companies will let you learn the skills as you go other companies will expect you to “hit the running”.

Removal of high quality

For those of you who have followed my website for sometime you may have noticed I have removed something from my website.

Can you guess what it is? Yes it is the word “high quality”.

My websites description use to read …

“Freelance Web Software Developer from Derbyshire, UK. I write high quality code to create and deliver web based software projects.”

And it now reads this …

“Freelance Web Software Developer from Derbyshire, UK. I write code to create and deliver web based software projects.”

I do not know why I said I produce “high quality” code in the first place, what did I hope to gain from this?

James Barnsley A produces code to power websites.

James Barnsley B produces high quality code to power websites.

Is a potential customer going to read my website and think …

Oh well, I had better go with James Barnsley B then instead of James Barnsley A. It is highly unlikely is it not?

I wrote about this in a previous article which has now been deleted but I will describe what happend again for the benefit of the people who never read the article.

A while ago I rang up a company who I was looking to work with and I explained to one of the people at the company about myself, the customers I have worked with and that I do programming.

I also mentioned that I do programming as a hobby and immediately in a raised voice the person blurted out …

“We do programming as a profession here, we do not do it as some hobby, we are doing this for a living!”

Yes I get that, hence the reason I talked about myself and the customers I had already worked with, some of which are multi-million pound organizations.

Anyways for some reason the person ignored all that and obviously just thought I was a “hobby” programmer.

I actually did programming as a “profession” and then in my spare time did it as a “hobby” also by working on my own personal projects.

There are a lot of these turning a hobby into a job articles online that all follow a similar theme, here is one of those …

The theme generally takes the story of a person who is doing something for a hobby like programming and then after a number of years of doing it as a hobby the person had a moment of “enlightenment” and all of sudden he is no longer doing it as a hobby anymore but as a job.

The person makes all the analogies about he “tightened up his processes”, “defined what he really wanted to do” and how his “programming improved to such an extent that he is no longer doing it as a hobby but as a job”.

The person has left all his / her “hobby” programmers behind because their just not there yet and have not reached the level of “enlightenment” that he / she has. Yes, a person should always wear his “hobby” programmer badge with pride until he has reached the “next level”.

Let me turn my hobby into a job …

“I am James Barnsley and I do web programming as a hobby job”

After thinking about this I can see how that related to myself.

I started out as James Barnsley who writes code to power web software systems. Now James Barnsley has had a number of years experience at doing this James Barnsley is no longer just James Barnsley but is James Barnsley who writes “high quality” code to power web software systems because James Barnsley says so.

Jon Smith starts out as a “hobby” programmer who writes code to power web software systems. After a number of years Jon Smith is no longer Jon Smith the “hobby” programmer who writes code to power web software systems but is Jon Smith the “professional” who writes code to power web software systems because Jon Smith says so.

In reality neither the word “hobby” or “professional” was needed.

So basically once I got “self confident” enough I decided to stick the word “high quality” in the paragraph. I felt I had reached a “new level” and I needed to inform potential customers of this by sticking the “high quality” label on my website.

Why was James Barnsley not “high quality” at the beginning of his programming practice?

Why is James Barnsley “high quality” now?

Why is James Barnsley “high quality” in the future?

Yes “high quality” is a subjective term anyway, but I do not want get into that. The simple point is that “high quality” is just a label. I could have stuck “high quality” on my website at any time I choose to, it means nothing. Even if I was “high quality” it still means nothing.

These labels can become something that haunt you, they can become something that control you, they can become something that irritate you as shown in the reaction of the person at the company I rang.

The person was probably only defending himself and his company but the word “hobby” or “professional” should not matter, should it? What if my code as a “hobby” programmer was greater than his code as a “professional” programmer.

If I take the humble approach it does not matter whether I got a “very bad” or a “very good” label applied to me because I am none of these labels.

These labels are trying to get me to form a conclusion about myself.

An example would be let us say someone said “I look very beautiful” and I accept that label about myself.

What happens if that same person or another person now comes along and says “I look ugly”. I would be devastated right? This is because my value is now being derived from these labels.

Now what happens if I consider myself none of these labels and I truly believe this to be the case.

A person comes up to me and says “I look very beautiful”, well instantly I know this does not apply to me.

Now someone comes along and says “I look ugly”, well instantly I know this does not apply to me.

So you can get what I am getting at. If I accept either label “beautiful” or “ugly” I have really done myself a dis-service have I not?

You could say I only accept positive labels about myself but this is unlikely as someone who accepts positive labels about themselves is bound in way to accept negative labels about themselves.

Accepting the labels means it has opened you up to attack i.e. now that you have accepted you are “beautiful” we can get you to accept that you are “ugly” right?

This is what I mean even if I am “beautiful” and it is true that I am “beautiful” the word “beautiful” has no part of me. It can be true that I am “beautiful” or “ugly” without those labels belonging to me.

There is a difference between these labels and me even if some of these are labels are true.

When someone says you are “beautiful”, “great”, “fantastic”, “ugly”, “a prat”, “worthless”, “substandard” or whatever, do not be so quick to accept the label, even if it is true. The “truth” can belong to another person without having to belong to you in the same way a “lie” can belong to another person without having to belong to you.

I heard somebody suggest once …

“If someone is making comments on you “good” or “bad” then you mean more to them than they mean to you”.

I do not believe this to be the case. You may not mean anything to the people who are applying these labels to you and as stated earlier if you accept these labels then you may be doing yourself a dis-service.

So anyways going by this more humble interpretation and because putting “high quality” on my website is not going to make a difference in the clients that I get I have decided to remove “high quality” from my website for these reasons.

Agency vs freelancer my opinion

So I read a lot of articles online about “Agency vs freelancer” the subject of the article being from a client point of view which is best to go with in terms of completing a project successfully.

Sometimes I read the article on a general web development article website which is fine. However sometimes I read the article on a web agencies very own website.

I have possibly written similar articles in the past on this website which I have now deleted and let me tell you why in my opinion it is not a good idea for multi-employee agencies to post articles like the above in their blog.

So let us be honest the article is intended to big up the agency whilst making the freelancer look like a bad choice. This is the fundamental intent of the article and that is why it was posted to the blog in the first place.

Whilst on the surface the article seems to do this there is another underlying tone to the article in my opinion which communicates a different message.

The message it communicates is that the agency views the freelancer as the competition. Writing “Agency vs freelancer” or similar as the article the agency has automatically created the freelancer as the competition. This massive, cutting-edge, leading agency views this small, tacky freelancer as the competition?

This is similar to say Rolls Royce viewing themselves in competition with Ford. Ford does not lose any sales to Rolls Royce and Rolls Royce does not lose any sales to Ford, they are at completely different ends of the market.

The article can give an impression that is at odds with the articles intended purpose.

Having said all this I will also say that there is one other area I will mention in relation to articles such as the above.

Many of these articles attempt to portrait that an advantage of going to an agency is that you get a “team” of people working on your project vs the 1 person freelancer working on your project.

The way this is generally written in the article tends to try to give the following impression …

Freelancer hourly rate = £50
Agency hourly rate = £100

Wow, I am getting a full team of people working on my project rather than the 1 person freelancer for only double the price.

Errrrmmm, not quite. You see that is £100 per hour. So for an agency of 8 people that will cost you £800 per hour. The result is more like as follows …

Freelancer hourly rate = £50
8 person agency hourly rate = £800

You are still paying by the hour no matter what way you look at it. You just happen to be paying double per hour in the above example to have 1 person work an hour for you from an agency.

Let us face it, freelancers have contacts as well and I am certain that if you where willing to pay the freelancer £100 an hour it would not be very hard for the freelance to get some external resources into the project himself thus forming a mini-agency.

Infact you could have just given the freelancer the break he needed to expand his business himself into an agency.

Tips for freelancers

Here are my tips for new or existing freelancers. Looking around the web there are many articles that discuss this theme and they all seem rather identical to each other.

I personally get bored of reading these after a while but I can promise you that even though some of the ideas discussed in this article may be similar to other articles, they are all my personal tips. Each one of these tips is important even if they may seem generic …

Shared office space

Certain situations may happen whilst freelancing when you need the advice of other freelancers. Preferably this would be face to face advice. When working in a shared environment with other freelancers this gives you the opportunity to get the needed advice right at the time you need it.

You may think that having your own private office is better as it avoids interactions with others but this can be a lonely road and getting advice on internet forums or through Skype just does not have the same effect.

Also being around other freelancers can provide a motivational boost to your energy levels as well as providing opportunities you may have missed whilst working in a private office.

Sell yourself as an individual

If you are freelancer then sell yourself as a freelancer. At a certain point in time a client is going to know that you are individual and not a group of people anyway.

A client will wonder where the rest of the company is, at that point you will have to explain that the company consists of just yourself. Save yourself the hassle and just sell yourself as a freelancer.

Payment schedule

Agree to a payment schedule with your clients and stick to it. Preferably agree a payment schedule where you are always paid in advance so you are never having to do work that you have not already been paid for.

Hourly rates

Charge hourly rates for your work. Quoting for fixed price is always a headache.

Even if you think you have everything covered in your fixed price contract the requirements of the contract can be too subjective and no matter how detailed it appears some of the requirements will always be left open to interpretation i.e. client wants a new kitchen, you build him the kitchen, client actually wants a kitchen with gold work surfaces.

Yes you can argue that you have provided the kitchen thus fulfilling the requirement however the client will also argue that the gold work surfaces came under the “new kitchen” requirement.

Arguments can then happen, clients may threaten legal action, you are a 1 person freelancer against the larger client company. You can take this risk if you want to or you could just save yourself the hassle and charge hourly.

Sustainable hourly rates

You may find that you will not always have a full schedule of work as a freelancer. There are gaps in the work flow and other expenses that need to be accounted for.

Clients will always know someone who can do it cheaper but the bottom line is it does not matter what Bill or Joe next door charges for their freelancing services. Your hourly rates need to be sustainable.

If you do not have sustainable hourly rates then you will not have a business for very long. This business has got to support you if it does not then it will not last.

There is no point in charging cheaper rates to get work if those rates are not going to sustain your business.


Adopting the “hourly rate” idea earlier your contract should be reasonably straightforward, an hour of work done, an hour of work paid.

Charging by the hour takes some of work out of the contracts as you not agreeing to a requirements specification on a feature by feature basis.

Always have a contract though nevertheless, contracts provide help when dealing with client disputes.

Client profiling

Do not just accept any client that wants you to do work for them.

Profile the client …

  1. What are the clients good and bad points?
  2. Does the client value your work or see you as a commodity?
  3. Is the client someone you really want to work with?

Come up with a profile of the clients you want to work with and only or at least mostly only work with those types of clients.


Have a clearly defined process for dealing with clients from on-boarding, design, development, testing, delivery and on-going work.

Every freelancer will have a process of some sort but it is important to get the process defined and written down.

The process is good material to present to clients thus helping with marketing activities. The process is important to you as it improves reliability.

Consider these tips if you are a freelancer or are new to freelancing.

Select2 library solution in Yii2 part 4 – retrieving the data

To continue on from the previous article I wrote about saving the Select2 data …


I will now talk about how to the retrieve the stored Select2 data so that the data can be displayed on the front-end Select2 field. Following on from the Task / Countries example, place the following “loadSelect2Items” method inside the Master model or Task model if you did not create a Master model …

The code above can be explained as follows …

  1. Line 3 – return the array of Select2 data using the “array_map” function
  2. Line 4 – store the related entity models name into a variable, in this case that would be the Country models name. This uses the Country relationship that was created in “Part 2” of this article series
  3. Line 5 – store the IDs of the related relationship entity model in the return data, in this case that would be the IDs of the Country model records
  4. Line 6 – find all the records for the model / model property in the “select2_data” table, in this case that would be the Task model and “countries” property

The next step is use the “loadSelect2Items” in the Task model to the load the Select2 data into the “countries” property, place the following inside the “afterFind” method of the Task model …

So that concludes the Select2 library solution for Yii2. I have covered the creation of the necessary database table and the read / write methods for reading / writing the data.

After the initial methods have been setup this solution will provide you with a way of easily putting a Select2 field on your forms that allows for many to many relationships between models with just a couple of line of code.

Select2 library solution in Yii2 part 3 – saving the data

To continue from the previous article …


Once the database table has been created the code can now be written to display the Select2 field on the form and save the Select2 data to the database table.

In this article I will demonstrate the Select2 functionality as though we are wanting to add “Tags” to a Task model. When I say “Tags” I mean the standard web term for Tags. Essentially these are words that you can tag to an entity for example a WordPress article that categorizes the WordPress article using the tags allowing a user to search by those words.

When I say Task model, this is a fictional model in a Yii2 application that will allow the user to create and update tasks. For the purposes of this article it is assumed you will create your own Task model along with the controller and views. Create a standard CRUD for tasks possibly giving each task a name and a description.

You will need to create a Tag database table to store the Tag data along with its associated model. Create a database table with “id” field for the primary key and a “name” field to store the Tag name. Create a standard Yii2 model for the Tag table, this model does not need any methods inside it, it is a blank Yii2 model that extends ActiveRecord.

After you have created your task CRUD functionality and the Tag database table with associated model the Select2 functionality can be integrated.

First the field is added to the form using the Kartik Select2 plugin. The plugin can be found here …


Add the field to the form using code similar to this. Include the plugin in the form …

Add the field to the form …

Create a “tags” property in the Task model, this will be used to store the tags field data on both saving and retrieving …

Now the field is added to the form and you have a property in which to store the array of data which the Select2 library needs in order to function. Next you need to use the “saveSelect2Items” items method as shown below to save the array data in the “tags” property to the database.

The “saveSelect2Items” method can be placed inside the Task model but it would be better in some kind of global area such as a Master model as is it likely that you will want to use the functionality in more than one model / form. I wrote an article on how to create Master models which can be read here …


The “saveSelect2Items” method is as follows …

The code above can be explained as follows …

  1. Line 3 – get the class name of the model object in this case that would be the Task model and convert it to lowercase characters
  2. Line 4 – get the class name of the store model object in this case that would be the Tag model and convert it to lowercase characters
  3. Line 5 – get the Select2 array data of the model object in this case that would be the “tags” property in the Task model
  4. Line 7 – if the model object Select2 property is not empty, in this case that would be the “tag” property
  5. Line 9 – get the current stored records in relation to the model and model properties we are using. In this case the Task model, Tag model and “tag” property
  6. Line 11 – loop through the currently stored records
  7. Line 13 – if the related model object ID is not in the model object property array data. In this case that is if the Tag ID is not in the “tag” property array data
  8. Line 15 – set the deleted flag to 1, which indicates deleted
  9. Line 16 – save the record
  10. Line 22 – loop through the array data in the model object property, in this case that is the Task model “tags” property
  11. Line 24 – check to see whether a record already exists in relation to the model and model properties we are using. In this case the Task model, Tag model and “tag” property
  12. Line 26 – if no existing record can be found
  13. Line 28 to 33 – create a new Select2 record and set the properties
  14. Line 35 and 36 – save the new Select2 record but if it does not save then return false
  15. Line 42 – the else part of the original if statement, if there is no array data in the “tags” property
  16. Line 44 – delete all the existing records for the model we are dealing with. In this case that is the Task model

As mentioned in the database article the “saveSelect2Items” method soft deletes the unwanted Select2 records with a little adaptation this could be altered to hard delete the records.

Now that the “saveSelect2Items” has been created you can call it in your Task model by placing the following code in the “beforeSave” method of the Task model …

The first parameter of the “saveSelect2Items” is the property used to store the Select2 array data, the second parameter is the original model that uses the Select2 field on the form in this case that is the Task model. The third parameter is the relation model in this case that is the Tag model.

The code up to this point puts a Select2 field on a form and saves the Select2 data when the form is saved. If you go back to the form the Select2 field will not be populated with the saved data yet as that is covered in the next article which talks about retrieving the Select2 data.

Select2 library solution in Yii2 part 2 – database

To continue from the previous article …


I will now talk about the database table needed to get my implementation of the Select2 library working. As mentioned earlier the original design for the database included a table for each set of Select2 relations. So if I wanted a Person to be able to select multiple Countries I would have a Select2 PersonCountries table, 1 table per relation.

The latest design for the database has just 1 table to store all of the Select2 relations used throughout the web software application. I find this easier as I can then use the Select2 like a module, whenever I want Select2 in my web software application I just drop in the code files along with the database table.

The database table I am using is as follows …

I will now run through what the columns in the database table are used for …

  1. id – unique integer for the record
  2. entityModel – the short name of the model class stored in lowercase characters, for example the “Person” model
  3. entityModelField – the name of the model property used on the form to select the related Select2 relations, for example “countries”
  4. entityModelID – the ID of the model, for example the ID of the “Person” model
  5. relationEntityModel – the short name of the related model class in lowercase characters, for example the “Country” model
  6. relationEntityModelID – the ID of the related model, for example the ID of the “Country” model
  7. deleted – a flag to determine if this record is deleted
  8. createdBy – the ID of the user this record was created by
  9. createdDate – the date this record was created
  10. updatedBy – the ID of the user who last updated this record
  11. updatedDate – the date this record was last updated

Please note that “id” is just a standard primary key and is not unique to this article also deleted, createdBy, createdDate, updatedBy and updatedDate are not unique to this article. These are just standard columns that I populate all of my tables with and are not really necessary for the purposes of this article.

The deleted column may be necessary if you are running the code exactly as explained in this article but the record could have just as easily have been hard deleted and hence the deleted column is just personal preference.

To know more about the standard columns I use and to auto populate these columns read the following article …


The above database table is the table I use to power the Select2 library relations in my web software applications. An example use case for this can be described as follows …

You have a update Person form (entityModel) with a countries field (entityModelField) that allows the user to select various Countries that are related to the person (the ID of the Person is the entityModelID). You can select various Countries and save them to the Person. For each country saved a select2_library record will be created, the ID of the Country is the relationEntityModelID and the Country model itself is the relationEntityModel.

At this point a Select2Library model will need to be created for the “select2_library” table. In the example used in this article a relationship will need to be created between the Select2Library model and the Country model. This will need to be created using the “relationEntityModelID” like this …

All of the above will become clearer when actually running the code and seeing the results. The code to get this to run will be described in the follow up articles.

Yii 1 to Yii 2 differences and enhancements part 1

A number of months ago I made the switch to the Yii 2 framework from the Yii 1 framework. My intent in this post is to outline some of the differences and enhancements I have found from switching to the latest Yii framework.

A framework is a set of code written to help in common programming tasks for example handling data, creating forms and data tables etc.

When I first started programming I did not use a framework as I did not understand the benefits properly of using a framework. The above tasks would have been written from scratch and would have essentially duplicated code that was already out there for solving these common tasks.

When I first started using a framework it made my life much easier and the end product was of a better quality to time ratio than not using a framework. The same quality could be achieved without the use of a framework but would take longer and the programmer would be essentially writing code for common problems that already have a solution.

I would also like to mention that frameworks provide a consistent structure to the code that a programmer writes so that one way of solving a problem at one end of the code would be the same way the problem was solved at another end of the code. This makes it easier for other programmers to understand the code base.

After using the Yii 2 framework here are some of the differences and enhancements that I have found …

User Identity

In Yii 1 a “User identity” is a class that extends “UserIdentity” and handles the authentication and identity of the logged in user. I would create a class that extends “UserIdentity” create some predefined methods and let Yii handle the authentication.

In Yii 2 a similar approach is used except I do not create an extended “UserIdentity” class but instead I “implement” “IdentityInterface” in my User class. In Yii 1 I would have a “UserIdentity” class and a “User” class, in Yii 2 I just have the “User” class. Similar to Yii 1 I create some predefined methods in my “User” class and let Yii handle the authentication.

Active Record

Active Record has some key differences going from the Yii 1 framework to the Yii 2 framework. In Yii 1 Active Record was used like so …

Or …

Or …

In Yii 2 Active Record is used as follows …

Or …

Or …

Basically in Yii 1 there where a lot of methods that where created for specific purposes “findAll”, “findByPK”, “findByAttributes”, “findAllByAttributes”, “deleteByPK”, “deleteAllByAttributes” etc.

Yii 2 can do all of the above purposes but the syntax is much more flexible in that it does not have methods for each purpose but flexible syntax that can be used for flexible purposes.

Also note how in Yii 1 I used array() and in Yii 2 I used []. That is because at the time of Yii 1 array() was the PHP syntax used for creating arrays and at the time of Yii 2 [] could also be used to create arrays. Not really a Yii issue but still the array syntax looks better in the more modern version of PHP.


Due to the Yii 2 framework being written at a time when the version of PHP was later and more modern the Yii 2 framework has made extensive use of the “Use” statement and “Namespaces”. Yii 1 did not make use of these at all probably because they where not implemented in PHP at the time the Yii 1 framework was written.

Nevertheless I feel the “Use” statement and “Namespaces” give the code a more professional feel and it means that the code is only made use of when the code is needed.

I will be updating the blog with more articles on Yii 1 to Yii 2 differences and enhancements as I go a long. I already have plenty of differences lined up but I will be saving them for the next article in this series.