Where to place widgets in Yii2 application

70 views Asked by At

I'm using Yii2 to create my application. I also like to use the widget feature, but I'm not sure, what is the best practice for the widget code location. The Yii2 directory-structure provides 2 directories:

  1. @app/components
  2. @app/widgets

The location "2." (@app/widgets) sounds like the best location for widgets. But, the Yii2 documentation for widgets used the location "1." (@app/components)

So my question: what is the right place for own widgets?

1

There are 1 answers

2
mariovials On

I put it in @app/components/*.

There I also put

@app/components/widgets/*
@app/components/helpers/*
@app/components/validators/*
@app/components/otherComponent/*
@app/components/MyActiveRecord.php
@app/components/MyController.php

and other components of my application