Am I Using Yii 2 Correctly?

Hello there.

I’ve been experimenting with Yii 2 beta and I plan to use it for an upcoming project (I don’t mind BC breaks). I’ve never used any flavour of Yii before.

The question I have is whether I’ve missed something regarding initializing a Yii app instance.

Currently I’ve got my own index.php which creates an instance of \yii\web\Application and calls the run method. I actually quite like this, but it’s something I’ve not encountered in any other framework I’ve used before so I’m wondering whether there’s something I’ve missed i.e. whether there is an existing “index.php” that does all of this?

Additionally, I’ve had to quickly put together some code which looks in a certain directory for bootstrap .php files to set up modules and things I want to use. For example, I’m planning to use Laravel’s Eloquent, which requires the setup of a container and such. In other frameworks such as the aforementioned Laravel, this would all be done in service providers. Is there an existing mechanism in Yii 2 for this? I suspect it may tie in with modules somehow.

Thanks in advance.

Hmm. Seems like you’ve installed advanced temlate and forgot to run ‘init’ file, that creates (copies) this file.

Thanks for the reply. My method of installation was just adding “yiisoft/yii2-dev”: “2.0.0-beta” to a composer.json and running composer install. Is there something I’ve missed?

Yes, you need to run the steps in the Getting Started Section of the advanced app guide.