Finding your way around Yii 2

Now you should have everything you need installed on your box, so let's start looking around and see how Yii 2 is organized so that we will know where to put our hands when needed.

Remember, there's always a README.md file you can consult: in the advanced application, it will show you the structure and use of the various directories.

By just listing the content of the root of the project, you will immediately spot a big difference:

$ tree -L 1 -d
.
├── assets
├── commands
├── config
├── controllers
├── mail
├── models
├── runtime
├── tests
├── vendor
├── views
└── web

11 directories

I've willingly excluded the files from the output of tree and displayed only the directories.

It seems like all the content of what once was in /protected have been dropped outside of the document root.

The project structure is now very similar to what could be a Django or a Ruby on Rails application; the project root contains all the code, which is organized the same way as it was in the protected folder (for example, controllers, modules, config, and so on), some additional directories, such as for widgets, and the document root for your web server.

The directory you will need to configure Apache to use is called web, and it's used by Yii to ship only the static files, assets, and the entry scripts, as shown in the following:

$ tree -L 2  web
web
├── assets
├── css
│   └── site.css
├── favicon.ico
├── index.php
├── index-test.php
└── robots.txt

2 directories, 5 files

I tend to prefer this organization as it gives the user the immediate idea of the organization of the code by lowering down the nesting levels of the directories.

If you are keen on using Nginx, that's not a problem, and you will find the required answers in the official documentation, which can be found at http://www.yiiframework.com/doc-2.0/guide-start-installation.html#configuring-web-servers.

The only two directories that require a bit of explanation are mail, which is used to store the HTML template(s) for the e-mails (see documentation at http://www.yiiframework.com/doc-2.0/guide-tutorial-mailing.html), and, possibly, tests, which you will be learning soon.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset