Yii 2 Avanced Template

A question I’ve seen on numerous occasions in the Yii 2 Forum is should I use the Yii 2 Advanced Template or the Basic Install? The answer to this depends quite a bit on what you want to accomplish and how. The first thing to mention is that if you are considering this question, you really should install a copy of both to get a hands on feel for yourself.

The instructions for installation of basic are here in the Guide. The instructions for the Yii 2 Advanced Template Installation is here.

Now if you are familiar with this blog, you know that I’m a big fan of the advanced template and that I use it in my book, Yii 2 For Beginners. It’s a little counter-intuitive, but I actually found that easier to work with than the basic application. The reason for this is that in the advanced template, they provide a fully-functional, database-driven user model, which is out of the box ready to register and login users. You even get the forgot password functionality, working out of the box, so you don’t have to code anything for that either.

So I found this to be incredibly helpful when I was new to the framework and I still feel strongly about it now, it’s a great template. The basic application is awesome too, after all, it’s the same framework. And depending on your application needs, it might make sense to start with that.

In my view, if you are just learning the framework, I think it’s easier to get started with the advanced template, even though you have to do a little more work in configuration and with the second host entry for the backend. Any medium to large size project would probably want separation of backend and frontend areas of the application, so the advanced template gives you a working blueprint for that. And considering it was made by the same team that developed the framework, it’s a strong blueprint. You can learn a lot from it.

Although they give you a working user registration and login in the advanced template, it’s only a starting point, and you still have to implement your own RBAC and any special logging that you might want to do, recording the ip address of the user for example.

Yii 2 does include an RBAC component that you can use with either template, and it is now well-documented and feature rich. I don’t use this implementation in my book, going for something simpler because I prefer to be closer to the RBAC code, so I can modify it more easily. It’s one of those things that just seems like I would have so many custom requirements that it’s just easier to go my own way with it. But that’s not to say anything negative about the Yii 2 RBAC, it’s really cool and ready for you to use if it meets your needs. It’s just another awesome feature that the framework provides for you.

In a sense you could apply the above statement to things like the user model, depending on how you wanted to build your application. So for example, if you had some custom implementation of a user model that was just too different from the advanced template, you could simply build it from scratch with the basic application.

Also, the way the backend and frontend are divided in the Advanced Application is obviously not the only way to do it. Some applications will not require a separate backend, though this is probably a minority. In smaller apps, you don’t necessarily even need a separate set of directories for backend, but keep in mind that apps tend to grow over time, so in my view, it’s best to account for this upfront. The advanced template is perfect for this. But you could also structure your backend differently by setting it up as a module.

Personally, I like the Advanced Template, I think it’s the perfect starting point for a medium to large application, or maybe even a smaller application where there is enough of a backend to imagine managing users through a backend UI.

Another thing I really liked about the advanced template, getting back to what I said earlier, is that you get to see a beautiful implementation of the user model that you can learn from, especially when you are just learning the framework.  For example, did you know that the Yii 2 Advanced Template doesn’t use a password field in the DB?  Instead it uses password_hash, and you can get the full details on that by doing the setup.  It’s just a great example of a user model.

In another example, when I wrote my Super Simple RBAC Tutorial, which gets you a working RBAC for the advanced template in 6 easy steps, I looked at the methods on the User model and the form model and followed their format and it really helped, everything just flowed beautifully. The point being that for newer and beginning programmers, learning how the framework does things is very useful and instructive and will help you progress faster in the long run.

If your are part of a team of professional developers deciding which version to use, basic or advanced, just keep in mind that both are equally capable of delivering enterprise level performance. So it just makes sense to see if the Advance Template represents a good starting point or simply will end up getting in the way, and obviously, no one can answer that question for you, you have to decide that for yourself.

Thanks again to everyone from around the world who has supported my blog and book. Feel free to contribute with your own comments, links, and reviews, it is greatly appreciated.

Advertisements

5 thoughts on “Yii 2 Avanced Template”

  1. Hello Bill, thank you for the book you have written! It helps me to make steps forward in my development in yii2.

    Now I have a question. I want to create a module using advanced template.
    This module is going to be used by both frontend and backend. But not in the same way.
    I assumed that in this case I should put it in a common folder and leave my models of my module over there.

    But then how it would be better to organize the rest part? Should I re-create the same module both in backend and frontend with appropriate controllers and views and use models from common folder?

    I hope I managed to explain what I’m looking for.

    Thanks

    1. Thanks for your positive comments about the book, they are really appreciated. I will continue to update the book in the future, so more material will be added. The next update is coming in January.

      Please refer to the Yii 2 guide for use of modules, it’s not a topic that I cover for beginners.

      That said, I think that you are referring to something else. You can create a common model in the common models folder and then extend it in frontend and backend to take into account differences. The Yii 2 guide recommends this way of doing it.

      So you would have

      \common\models\NewModel

      \frontend\models\frontendNewModel extends NewModel

      \backend\models\BackendNewModel extends NewModel

      Obviously, BackendNewModel extends NewModel is not the name of a file. Anyway, hopefully that can give you a quick idea of what to do. Then you would just use Gii to create CRUD off the extended models, not the base model, so you would get your differences.

      Thanks again for your kind words on the book and good luck with your journey on Yii 2, it’s an awesome framework, and very worthwhile to learn.

      1. thank very much Bill for your response.
        And good luck with new updates of your book! Looking forward to read it

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s