Tag Archives: learning a php framework

PhpStorm 8.0.3

I recently made the switch to PhpStorm from PhpED and I love it. So let me first say, there’s nothing inherently wrong with PhpEd, it’s a fairly solid editor, and it’s probably capable handling more than I am aware of. We used it at work, so that’s how I ended up using it. But recently, we have changed our development environment, and our team chose PhpStorm.

This turned out to be extremely helpful to me. And a big part of the reason for that is that Laracasts has 23 videos dedicated to PhpStorm. Also, just a side note, these videos are free to watch, so you don’t have to be a subscriber, though I wholeheartedly recommend subscrbing, especially if you are using Laravel.

Another side note, if you are using Yii 2, then check out DoingItEasy on Youtube. These are very helpful videos, especially if you are working through my book Yii 2 For Beginners.

So, getting back to PhpStorm and Laracasts. Until I watched the series of videos, I never really understood the true power of an IDE. And actually, I’m still just learning. But I thought it was important to share some thoughts because I had some unexpected benefits from using PhpStorm.

The first one probably has the biggest impact, which is creating a custom color theme. This doesn’t sound like something significant, but it turned out to be very significant for me.

For one thing, when I made the switch off of PhpEd, I had trouble with the default themes that ship with PhpStorm. Monokai and Darcula, two of the default themes seemed to be the most popular at work, so I tried them. I found the themes to be noisy, with eye-popping colors that interfered with my ability to read the code. It was awful.

I thought I might have to switch back to PhpEd, but that wasn’t really an option, since the team needs to be on the same editor. So I started searching around and I found Dayle Rees’s Color Schemes and reviewed all of those.

While there are a bunch of interesting themes there, I still felt disconnected from them. Another thing compounding the problem is that my eyesight is not that great and it doesn’t take much for me to suffer eye-fatigue. It’s a real problem.

Fortunately, because of Jeffery Way’s videos on Laracasts, I was able to learn how to customize the theme. So I literally spent 5 hours working on a single theme.

I certainly didn’t intend to spend that much time on it. When I looked up at the clock when I was done, I was amazed, because I just pushed through without a break. Crazy. On the other hand, it really paid off because I ended up with a theme that is pleasing to look at and helps me understand my code more quickly. That’s because the color associations are not just pretty, they have intent. The color of methods is related to Classes in just the right way for me, so I can easily understand the relationships. Parameters are distinguished from variables, etc. I found just the right balance of colors that give me hints, but not so much diversity that I can’t untangle the noise.

When I get around to it, I will probably post the settings file on GIT, to share it. But it probably won’t have the same effect for others as it does for me. That’s why customization is so important. You can find the theme most helpful to you by building it yourself. I would highly recommend doing this.

I would write instructions on how to do this, but really, the free videos are the way to go on that one.

Ok, a couple of other high points to mention. The live templates are just super cool. The way it works is you assign a string and action key to a custom template, so with a couple of keystrokes, you can inject a template into your code, a real time-saver.

For example, I use _c followed by pressing the tab key to create a new constructor. It doesn’t seem like much. It’s just a sight gain in efficiency from typing it out, but these slight gains are significant when you scale them out over time.

And of course the longer templates, form fields for example, are just a pleasure to work with. I type in textfield and hit tab and I have a form field waiting for me. You can also pop in the name of the field, and if you have set up the template properly, it will auto-populate the name into all the appropriate places in the form, such as label, fieldname, etc. This saves a lot of typing and time.

Programming time is precious. It’s like gold. Even the tiniest fragments have value. So any efficiency gain you get from your IDE is like putting money in your pocket.

One of the other features that has me really excited is the extract feature, where you can take a block of code and extract it to a separate method. I’m blown away at how well it works. This really helps clean up the code and make it more readable. And it’s so cool to see the choices the editor makes, you can learn from that as well.

PhpEd also has the extract function. Like I said, it’s not a bad editor. What it doesn’t have is 23 videos showing you all the cool things you can do with it.

There are a number of free editors as well, such as Netbeans and Eclipse, so if you are just starting out coding, you might want to try one of these first.

You can also customize your theme in Netbeans, not sure about Eclipse. PhpStorm just seems more robust. The only downside is the cost, but for me it’s worth it because I’m going to be spending a lot of time in my IDE and I need to be as comfortable and as efficient as possible.

A lot of pros also prefer Sublime, but I have no experience with that one, so I can’t really comment on it.

I’ll probably look into Sublime in the future, but for now, I still have a long way to go with PhpStorm for now.

Learning and mastering your IDE, setting up and memorizing all your short-cut keys, templates, color schemes, etc., can take years. But don’t let that intimidate you or cause you to put off learning it. Every little bit helps, even if you start slowly. And if you are like me, you will see dramatic improvements in your work flow as you become more comfortable with it, even when you are new to it like I am.

Yii 2 Learning Your First PHP Framework

I’d like to start today’s post with a big thanks for the positive reviews I’m getting on GoodReads.com, please add yours if you can.

Also, a big thanks to everyone who has emailed me with supportive comments for the Yii 2 For Beginners book and for the positive comments on this blog.

I’ve made it my mission to help introduce people to the wonderful Yii 2 framework, and I know from first hand experience how hard it is to get up and running on something as big as a PHP framework, especially if you’ve never worked with one before.

The decision to use one framework over another is a personal choice. The major frameworks that I talk about, Yii 2, Laravel, and Symfony, are all great frameworks. You have to pick the one that suits your development style and this can certainly be a challenge when you haven’t worked with them because how are you supposed to know how well it fits?

Well, it’s like expensive clothing, you won’t know if it fits until you try it on. Obviously I’m recommending Yii 2 as the first choice among the frameworks from my point of view. Here’s why:

Top 10 reasons I would start with learning Yii 2:

1. Yii 2’s Advanced Application Template. This template comes with a working user model that includes registration, login, and forgot password functionality right out of the box. It also includes backend and frontend separation, so that you are clear on how to structure your admin area. You can get up and running quickly.

2. Gii. Yii 2 has an amazing code generation tool named Gii, which helps you stand up your models, controllers, and views quickly. The generated code almost always needs refinement, but once you know how to do that, things move along with lightning speed. It takes about 2 minutes to generate 8 files, a model, a search model, controller, and 5 view files. You’ll be amazed how far you can go in so little time.

3. Clear MVC pattern. Yii 2 has folders named models, controllers, and views, so the application structure is just what you would expect from an MVC.

4. No Routing. Most of the other frameworks require you to explicitly name the routes through the site, which can be tedious and at times confusing. Yii 2 handles this automatically. Of course you can set things like pretty URLs and any other customizations that you need, but the basic routing is handled by the framework. This is makes it very easy and intuitive to work with.

5. Widgets. Yii 2 supplies an incredible number of widgets to help develop your application. They cover everything from GridView, Pagination, Forms, DatePicker, etc., it really is impressive what you get out of the box. The widget class is easy to extend, so you can quickly build your own widgets. And once you start using these, you will get spoiled very quickly because you will want to use them for everything.

6. Mobile-First Bootstrap. So right out of the box, Yii 2 incorporates Twitter Bootstrap, which of course is device-responsive, so you can jump into mobile-first design right from the start. Wouldn’t you love to pitch that to your client?

7. Validation Made Easy. Validation in Yii 2 is handled on the model, with a very intuitive Rules method that simply holds an array of settings. The settings include the name of the attribute you wish to validate, the validator, and the options.

For example, do you need to make your email addresses unique so two users can’t have the same email address? It’s one line added to the Rules method.


['email', 'unique'],

It’s that simple.

8. Behaviors. Yii 2 incorporates a method named behaviors in both the models and controllers and this is another intuitive winner. In models, behaviors are used to manage events, like automatically inserting timestamp for creating and updating records, which is a useful behavior for a model to have. You can see how intuitive that sounds.

On Controllers, behaviors help you manage access control, things like restricting pages to logged in users only. Again, very intuitive and easy to work with. You can reference some of the tutorials on this blog for examples.

9. Native ORM. So first, what is ORM? According to wikipedia:

Object-relational mapping is a programming technique for converting data between incompatible type systems in relational databases and object-oriented programming languages. This creates, in effect, a “virtual object database” that can be used from within the programming language.

It’s a perfectly scientific explanation, but I don’t find it particularly helpful. We can break it down to something more digestible.

In the simplest terms, the ORM manages how your application communicates with the database, greatly simplifying the syntax. Example:

return $users = User::find()->asArray()->all();

The above code returns all the users from the user table in an array. No having to open a connection, no SQL, no binding parameters, no specifying fetch mode, etc. It’s just one line that reads like a sentence. Look at how simple that is!

Because Yii 2’s Active Record ORM is native, it is integrated seamlessly into the framework, and this is one of the reasons why Gii is so effective at generating code. The other frameworks use Doctrine, which brings with it the excess baggage of their repository structure etc., and in my view, making it more complicated and less efficient.

10. Enterprise Capability. If you are just starting out with framework development, you are probably not ready to jump into enterprise development. But wouldn’t it be wise to learn the framework that can take you there? Learning Yii 2 ultimate builds value into your career as a programmer.

Ok, so that’s my short list of why I would start with Yii 2 as opposed to some of the other choices out there.

The key to learning a PHP Framework, if you have never done this kind of development before, is patience. Yii 2 hands you an amazing amount of features, but you have to be willing to take the time to learn them.

Another key to success in programming is this: Don’t quit. Just keep going until you get it. You will get it.

Yii 2 has a great community that is willing to help you. Also, I wrote a book that can get anyone with a moderate amount of PHP skills up and running quickly.

I’ve also augmented that with free tutorials on this blog, and I’ve also included bonus material into the book. Everyone who purchases the book gets the free bonus updates for the life of the book. I plan to keep working on it for the foreseeable future.

Working with a PHP framework is a journey, not a destination. It’s hard work but it can also be a lot of fun. I’m very happy to share this journey with you.

Thanks again for all the positive comments and reviews. As always, any comments, reviews, word-of-mouth referrals, are greatly appreciated.