Yii 2.0.6 Released

On August 5, 2015, Yii 2.0.6 was released. You can check out the official release announcement here.

This release has over 70 minor new features and bug fixes, including:

  • better migrations syntax
  • improvements in error handling
  • more control over ActiveForm using javascript
  • nested Yii::t() calls
  • extra session fields

I’ve looked over the changes and I don’t see anything that would conflict with the code in Yii 2 For Beginners.

Initially, when I tried to upgrade to Yii 2.0.6, I had problems and got an error:



  [UnexpectedValueException]
  Could not parse version constraint <=2.*: Invalid version string "2.*"

So I put in a request to the friendly forum and got the response I needed:

to fix this, do



composer global update #this will update the fxp which causes your constraint issue
composer update  

Once I did that, everything updated perfectly. I have not found any problems with my template using this update, so I think we’re all good. If anyone does notice something that fails due to version change, please let me know.

As always I appreciate the positive reviews, comments, and links. Thanks!

The Wealth Algorithm

I took a brief detour from PHP tutorials to write a book for people under 30 years of age, who want to become wealthy. It’s book that shatters a lot of myths, includes useful information, and is very accessible to a younger audience. I wanted anyone from age 14 on up to be able to understand it.

I’ve always hated wealth creation books because they seem so fake, and I almost didn’t write it for that reason.
What I always noticed about these kind of books is that they were always so vague. You never seem to get something concrete from them, other than the statement of “avoid debt,” as if it took a clever person to figure that one out.

But then I thought about how I could do it better. Now everyone’s path to wealth is unique because no two lives are exactly the same, so I can’t avoid generalities in my book either. But on the other hand, I’ve come up with some very unique techniques for how to achieve personal wealth.

I felt like the main wealth algorithm, which is something I’ve loosely defined throughout my book, 99¢ Wealth, is something worth sharing and could have a big impact on people’s lives.

This was all made possible by the first application I ever wrote in PHP called Timekop. I wrote it a few years ago, but never released it. The programming was pretty hacked up and useless, but the idea was really cool.

The application measured wasted time on a daily basis and scaled it over a lifetime, so I could see the effect of wasted time over the course of my life. The results were a real eye-opener. And ever since then, I have applied scale and engineering principles to more than just PHP.

My personal wealth has grown dramatically since discovering all this. These techniques work and are worth learning.

In the book, I use various calculators to sketch out a roadmap towards wealth. The examples I use are typically American because I am an American, but I think anyone from anywhere in the world can benefit from my work.

Obviously, if you are from another country, you can change some of the assumptions to fit your local environment. But the overriding principles are universal. And anyone can follow them.

Those of you who know me as a diligent writer of PHP tutorials and my book Yii 2 For Beginners know how much care and effort I put into my writing. I did my best to deliver something valuable to all my readers. It’s off to a great start with reviews, I hope more will follow.

My 99¢ Wealth book is not written for programmers specifically, but would still be a benefit to anyone who thinks like an engineer. In my opinion, engineers and programmers are some of the brightest people on the planet, so most will breeze right through the material. It’s an easy read for bright people.

I also decided to stick with Leanpub.com for the publication of this book. There are a couple of reasons for this. One, I’m not a fan of Amazon. Two, I’d rather support the smaller enterprise. Things worked out well with my Yii 2 book and the leanpub staff is very responsive whenever I have a question. I like their platform.

It’s true I could probably benefit from more book discovery on Amazon, but since my blogs get a steady flow of traffic, I figure I will be driving most of the traffic to my books anyway.

Throughout all of my work, I’ve endeavored to help younger programmers learn skills that will help them be successful in life. This book on wealth is an accessory to that.

I’ve priced the minimum cost of the book at $.99. At that price, I get $.39 royalty per book sold. So obviously I’m not doing this for the money. At 99¢, the book is accessible to just about anyone. With Leanpub’s variable pricing, you can pay more if you feel you want to support my work that way. I do appreciate every sale of every book very much.

Also, the comments, likes, and especially positive reviews, are all greatly appreciated and drive me to keep working. The best feeling I can get from something I’ve written is that it’s useful. So that’s my mission, to write the most useful books I can. I hope they continue to serve you well.

Yii 2.0.5 Security Patch Released

Yii2 released a quick patch for the ViewAction class. You can read the release here.

I had problems when I tried to run composer update and apparently they are aware of an issue on the composer side. So if you are following along with the book and already have installed the framework, I don’t recommend upgrading until the problem is solved.

If you are doing a fresh install, then you should be fine with Yii 2.0.5. I will follow up when the problem is solved.

I will also try to carve out time to build my app from scratch with Yii 2.0.5, so that I can have a current build handy for any issues that might arise. I anticipate this will take a couple of weeks as I’m in the process of completing another book, which I will be talking about on this blog.

Also, thanks so much for the great reviews I’ve received on GoodReads.com. Right now we are 4.68 out of 5 stars average with 25 ratings and 7 reviews. I really appreciate all the support I got with this book, so thanks again.

MVP Minimum Viable Product

According to wikipedia, the term minimum viable product, MVP, is a term coined by Frank Robinson, and popularized by Steve Blank, and Eric Ries. I find this to be a very powerful idea, and one that works hand in hand with using a PHP framework, such as Laravel 5.1 and Yii 2.

So what is MVP? It’s easy to mischaracterize MVP as a product with limited functions and features because while it typically does have less features than the typical enterprise application, the goal is not minimalism.

The idea with MVP is that you stand up the minimum number of features you need in order to collect data back from the users, so you can validate your business model as you develop it. You build just enough to allow yourself to follow the breadcrumbs of data, then follow that data like a compass to determine your sense of direction.

The speed at which you prototype and process this early feedback is important. The idea is to incorporate the customer feedback into the build itself, and you can only do that if you are testing and validating often enough.

One thing that’s great about this process is that it eliminates the old arguments between creative people about what will work. Instead, we simply let the customers decide.

The good news for those of us who use PHP frameworks is that they can really facilitate the MVP process, and that’s how we should think about it, as a process.

It’s a process that maps to the processes being adopted by entrepreneurs and lean startups.

Eric Ries defined 5 principles that drive the Lean Startup process:

  1. ENTREPRENEURS ARE EVERYWHERE
  2. ENTREPRENEURSHIP IS MANAGEMENT
  3. VALIDATED LEARNING
  4. INNOVATION ACCOUNTING
  5. BUILD-MEASURE-LEARN

The last one, build-measure-learn really encapsulates MVP. You might be tempted to quantify your job as programmer to simply program what the entrepreneurs ask you to do, and shuffle off the build-measure-learn concept as their problem, but doing so makes you less valuable to them.

On the other hand, if you take the time to plug yourself into their process, you’ll find yourself becoming invaluable to the enterprise. You’ll be part of the team that provides insight and clarity to the objectives, based on the intersection of design patterns and application usage patterns, the latter being provided by the customer feedback. The concepts developed in the code and the concepts of the enterprise fuse into a single entity and you will find yourself being a facilitator of this.

Leveraging the strength of a php framework can be an integral part of this process. For example, you might work for a company that doesn’t know the difference between building user RBAC from scratch and using or extending the options that are readily available to them from Laravel, Yii, and other frameworks. You can help guide them through these strategies and implementations. And if you can do it quickly, you will be their hero.

That takes us back to our php frameworks. When you study these frameworks, you can’t help but fall in love with them. There’s almost always core functionality or a plug-in to cover your requirements, so you can prototype very quickly.

The main thing to understand in a MVP approach is that it’s development on the fly, objectives change with the inflow of data, and decisions and implementations must be made rapidly. In the midst of this kind of environment, there is no difference between your love for PHP frameworks and the other tools that are available to you, such as Bootstrap, jQuery, and love of the enterprise itself. Your passion for development will help drive the enterprise.

I’m going to leave it at that. This article is meant to be a brief introduction to MVP. I recommend reading the wikipedia article and perhaps The Lean Startup by Eric Ries. I need to get a copy myself. Although I practice many of the principles, I have never actually read the book. Isn’t that so typical?

I can however vouch for build-validate-learn, though I would modify it to build-validate-succeed. Learning is not enough. Sometimes you only learn that you didn’t succeed. Those lessons are always valuable, but the real objective is success. Keep testing/validating until you succeed or pivot into something else.

Anyway, I hope you enjoyed this post. Please comment, share, and like if you can, thanks!

Laravel 5.1 Released

Laravel 5.1 is released today and it’s awesome. While there are only a few differences between 5 and 5.1, they are impactful, and really cement Laravel’s position as an enterprise framework. One of the most obvious changes is LTS, long term support, which fixes bugs (2 years) and security patches (3 years). This is obviously critical to enterprise development.

Another leap forward is the quality of the documentation. It’s incredible. Taylor Otwell wrote the documentation himself, and put the same obsessive care into the docs as he does the framework itself. This attention to detail really shows.

The first huge feature of the docs is the search window.  It’s easy to overlook, since I’m not used to using it and there is no label, but this is powerful.  It autocompletes what you are looking for and even does a good job of guessing on typos.  For example, when I typed in redur, it correctly understood I was looking for redirect.

Type in something like val and select validation.   Look at how great the Validation docs are. In the validation quickstart section, he begins with a route definition and takes you all the way through form validation, so it’s clear and comprehensive. We learn for example that all validation errors are automatically flashed to the session and are always available in the view through an $errors variable. Then of course we get a comprehensive list of validators.

If your validation requires a dependency, there is a great example, using the sometimes method to show you how to do it under the complex conditional validation section.

Another example of how thorough the documentation is the section on migrations. It’s a complete reference to:

      Creating Tables
      Renaming / Dropping Tables
      Creating Columns
      Modifying Columns
      Dropping Columns
      Creating Indexes
      Dropping Indexes
      Foreign Key Constraints

In the past I never really liked migrations, but I have come to appreciate them, especially since the workflow and execution on Laravel is so good.

The validation and migration sections are typical of the quality of the docs, I pretty much chose them at random.

Not only do great docs make it easier for beginners to find what they need, but obviously, they are a must have for enterprise development. Great documentation leads to coder happiness. Happy coders are productive coders. Productivity is essential for a successful enterprise.

Another change in 5.1 is the move to PSR-2 coding style, which is the one I’m most familiar with, so no complaints here.

Laravel 5.1 also introduces parameters on the middleware. If you are unfamiliar with the middleware class, it replaces the filters from previous versions of laravel. At first, I found this part of the structure a little complicated, but I have grown to appreciate it.

Basically middleware is a series of filters that are injected into requests via route definition or controller. They are super simple and easy to use, once you understand it, and once you see how it fits into the application structure. Not only that, but Laravel 5.1, like 5.0, has code generators for these specific classes via artisan, which will place them into the appropriate folders for you. So this helps you deal with the folder structure more easily.

While it’s true that new folder structures of 5/5.1 are way more complicated than what I was previously used to, they have had a curious side-effect. It’s actually easier for me to conceptualize or visualize the application as a whole. The discreet parts of the application make more sense to me. In the long run, the complicated folder structure makes application development easier and cleaner. You get far fewer overstuffed classes in favor of a greater number of leaner, more focused classes. It makes for cleaner code.

The release of 5.1 also includes the new @inject method for blade, which allows you to bring in a class instance from a service provider or helper class directly into your views. Normally, you would bring in all of your object variables into the view via the controller, but this could lead to code duplication. So, as in the latest example from Laracasts, if you have a stats object that you wish to use in many views, you can simply access it directly from within the view via @inject. This helps make code re-use simpler, since you don’t have to bind a view composer to a route.

Since I mentioned Laracasts, they have a bunch of new videos released today for 5.1, all worth checking out. Everyone here at work loves Laracasts.

The last new features that I’ll talk about in 5.1 are the model factories for seeding and the enhanced test integration. Model factories help automate the data seeding process, a very handy feature. It was already fairly easy to seed data and this just takes it a step further.

I’m going to defer to the testing video at Laracasts for the new testing improvements explanation, but I will say that it’s got the developers here excited about how easy it will be to test forms. It’s a huge plus.

For more info about the release, check out the Laravel 5.1 release notes.

Ok, so to wrap it up, let’s offer congratulations to Taylor Otwell and the rest of the Laravel team for releasing such a great enterprise framework. It’s through the work of teams like this that innovation and success becomes more accessible to all of us. It is much appreciated.

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.

It’s Laravel 5.1 for Enterprise Development

That’s a heck of a headline for a guy who wrote a book on Yii 2, certainly not where I expected to be at this point in time. When I first reviewed Laravel 5, I had an allergic reaction to it and wrote a snarky review on Laravel 5.0 (which I’ve since removed). So how did I go from that to recommending it for enterprise development?

Well, this transition started a few months ago, with the programmers in my company expressing a desire to move to Laravel. My first impulse was to say, “no way.” I had just spent a year preparing for our move into Yii 2. I fell in love with Yii 2 and wrote a 691 page book about it for beginners. I took a lot of pride in the book and kept working on it to make sure all the code worked and was clear and easy to understand. I got great feedback from the readers and have a 4.59 out of 5 rating on GoodReads.com.

So obviously it was a bit of shock to hear about laravel from the team. But rather than take a top down approach and dictate the framework choice, I wisely chose to open the topic to discussion and evaluation from programmers who are more advanced than I am. To keep up, I had to dig in deep and see if I could find what I felt I was missing. And the deeper I went, the more things started to tilt towards laravel.

To get there, though, I had to overcome my initial bias against Laravel, which based on the fact that Laravel was built on Symfony components, used Doctrine, and seemed to hardwire migrations into the workflow, at least in all the examples they were providing. So my objection was that it was slower, bloated, and not as database centric as I preferred.

In working with Laravel, however, I found that it wasn’t noticeably slower and the use of migrations led to a good work-flow, that if used correctly, could still adhere to proper discipline concerning the DB. Plus PHP 7 is on the horizon and it looks like it will eliminate most of the framework overhead, so the concern over using a framework that utilizes other big components like Symfony and Doctrine is no longer a significant factor.

Another thing that always threw me off with laravel was the obsession with the use of dependency injection. That never really clicked with me in the past, I just could never put all the pieces together to make sense of that. It somehow seemed gratuitous.

To put a little perspective on that, I always viewed coding to a contract as a more expensive proposition without a lot of upside. I thought it was an approach that was too intellectual, not practical, a better fit for java than for PHP.

I was 100% wrong about that. 100%. Wrong. Painfully so.

Anyway, the changes in laravel 5.0 and 5.1 really brought this to light. For example, their request class, combined with method injection is a very beautiful way of handling validation.

If a class is namespaced properly, you can inject an instance into either a constructor or method signature, without having to otherwise instantiate it, a nice piece of magic accomplished by reflection.

But even better than that, the service providers allow you to bind a concrete class to a contract, so you can call the instance of the class via the contract.

This makes changing the implementation of a class everywhere in your code as simple as changing one line of code. It’s awesome. That means you can test different implementations without having to create separate branches of your project, which makes it easier to manage.

One of the big features of laravel, one that moved our team sharply in their direction, is the ease of frontend integration using blade. It’s a super-clean template engine with crystal clear syntax. It makes working with bootstrap and jquery a snap. It also makes working with interspersed html and php very easy and clean.

There’s an old saying that fortune favors the bold. It may be a cliche, but it’s true. Taylor Otwell had a bold vision for laravel going back a number of years. In his book from 2013, he talked about changing the concept of model, long before laravel 5.1 came to fruition. And in some ways, it’s a counter-intuitive move, at least in the sense of moving things towards simplicity.

In a general sense, Occam’s Razor states that simplest answer is typically the most efficient. And I’ve always found that this is a great way to approach life, business and coding. But sometimes that can cause too narrow of a vision.

This is where Taylor boldly stepped forward. Fragmenting the idea of a model into smaller components is more complicated, but results in a more efficient workflow and maximizes the gains from loose coupling. While I can’t visualize the directory tree as easily, I feel more connected to the concepts, they seem clearer.

And while the structure is more complicated, the code generation via artisan takes this into account and helps you stub out handlers, service providers, middleware, and other class types, namespacing them for you and placing them in the proper folders in the application.

I don’t know how it is for other programmers, but I find most of the laravel syntax incredibly intuitive, and more so over time. This is not an accident. It’s all part of a cohesive set of principles and design patterns that are playing out perfectly at scale. It’s proof that the SOLID principles, and taylor’s specific implementation of them, actually matter.

So this was a huge attraction for our team, a sense of commitment from the path Taylor is blazing, that if we followed it, we would become better programmers. You know you have a future in programming if that idea excites you.

The title of this post is It’s Laravel 5.1 for Enterprise. One of the reasons for this is that Taylor has developed an entire suite of products designed to support enterprise development. These include, laravel(PHP framework), forge (server management), lumin(PHP micro-framework), homestead(local dev environment), laracasts(video tutorials), elixir (asset management), artisan (command line interface), and I’m sure I’m probably forgetting something. Oh yeah, envoyer, which gives you seamless deployment with no downtime.

The point is that laravel itself is run like a commercial venture, and this is a big plus for enterprise development. With 5.1, they have also announced long term support. So that means we can count on bug fixes and security patches for years to come.

And so now this brings us to laracasts. The story of the rise of laravel would not be complete without mentioning Jeffery Way and laracasts. Taylor is lucky to have him on his team, he is a world-class instructor, helping all of us stay on the forward edge.

While I could write an entire post about the great quality of laracasts and how useful the videos are, the really short version for now is that our company purchased a company license, so that all our programmers can have access to the videos on demand. The videos are that good. To borrow from another cliche, the videos contribute to programmer happiness, which is vital to the success of the company.

So this all worked out perfectly for my company, the programmers are happy with the decision to use laravel for our future development. But where does this leave me and this blog? Obviously this post is not going to boost book sales, at least not mine.

Well, I still love Yii 2. It’s a great framework and it taught me a lot about programming. I still recommend learning more than one PHP framework and Yii 2 is an excellent choice. I’m still proud of the book I wrote for it.

At the same time, I feel a sense of loyalty to everyone who bought the book and to the readers of this blog. Rather than simply just stay silent, I thought it was important to share my views and our company’s conclusions regarding framework choice.

Going forward, I’m going to be coding in laravel. That means at 691 pages and a translation into Spanish, my Yii 2 book is complete. It’s been a great experience, but it’s time now for me to move on to a new chapter in my coding journey…