Global Model and Controller


In Yii 1 I use to have a components folder where I put a global Model and Controller which all other Models and Controllers extend from. In Yii 2 I see no components folder.

What is the best way to accomplish the said action in Yii 2?


Create components folder and put your base models there.

Do I create the components folder in the web directory? Do I need to set anything in config?

Its OK I have done it.

Create components in root directory …


	namespace app\components;


	class Controller extends \yii\web\Controller {







Then use like this …



	namespace app\controllers;


	use app\components\Controller;

	class SiteController extends Controller {


		public function actionError() {







You can play with Yii 2.0 directories and overall structure as you want. It’s very flexible in this manner.